How can I get CGContextRef from UIImage?

CGContextRef context = ??; // get from UIImage *oldImage CGContextSaveGState(context); CGRect drawRect = CGRectMake(0, 0, 320, 480); CGContextConcatCTM(context, transform); UIImage *newImage = [[UIImage alloc] init]; CGContextDrawImage(context, drawRect, newImage.CGImage); [newImage drawInRect:CGRectMake(0, 0, 320, 480)]; CGContextRestoreGState(context); 

In short, I want to do this [UIImage → make transform → converted UIImage].

Any ideas? Many thanks!

+6
iphone uiimage cgcontext
source share
1 answer

I think you need the following:

 UIGraphicsBeginImageContextWithOptions(newImageSize, YES, 0); CGContextRef context = UIGraphicsGetCurrentContext(); // drawing commands go here UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

Note that UIGraphicsGetImageFromCurrentImageContext() returns an instance of a UIImage with auto-implementation.

+8
source share

All Articles