KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
After applying a 3d transform to an UIImageView.layer, I need to save the resulting "view" as a new UIImage... Seemed like a simple task at first :-) but no luck so far, and searching hasn't turned up any clues :-( so I'm hoping someone will be kind enough to point me in the right direction. A very simple iPhone project is available here . Thanks. - (void)transformImage { float degrees = 12.0; float zDistance = 250; CATransform3D transform3D = CATransform3DIdentity; transform3D.m34 = 1.0 / zDistance; // the m34 cell of the matrix controls perspective, and zDistance affects the "sharpness" of the transform transform3D = CATransform3DRotate(transform3D, DEGREES_TO_RADIANS(degrees), 1, 0, 0); // perspective transform on y-axis imageView.layer.transform = transform3D; } /* FAIL : capturing layer contents doesn't get the transformed image -- just the original CGImageRef newImageRef = (CGImageRef)imageView.layer.contents; UIImage *image = [UIImage imageWithCGImage:newImageRef]; */ /* FAIL : docs for renderInContext states that it does not render 3D transforms UIGraphicsBeginImageContext(imageView.image.size); [imageView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); */ // // header // #import <QuartzCore/QuartzCore.h> #define DEGREES_TO_RADIANS(x) x * M_PI / 180 UIImageView *imageView; @property (nonatomic, retain) IBOutlet UIImageView *imageView; // // code // @synthesize imageView; - (void)transformImage { float degrees = 12.0; float zDistance = 250; CATransform3D transform3D = CATransform3DIdentity; transform3D.m34 = 1.0 / zDistance; // the m34 cell of the matrix controls perspective, and zDistance affects the "sharpness" of the transform transform3D = CATransform3DRotate(transform3D, DEG
Tags (comma-separated)
Save Edits
Cancel