I am currently using the following code to write a CGContext to a PNG on disk:
CGImageRef image = CGBitmapContextCreateImage(context);
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *data = UIImagePNGRepresentation(myImage);
[data writeToFile:path atomically:YES];
I found that the orientation of the 开发者_运维技巧resultant file is flipped from the way it appears on the screen(on an iPhone). What is the best way to flip this image on save so that when I later load the image it will be up right?
The coordinate systems of UIImage and CG contexts are flipped from eachother. You can flip a CGContext by doing this before drawing into it:
CGContextTranslateCTM(context, 0, height);
CGContextScaleCTM(context, 1.0, -1.0);
精彩评论