开发者

Flip the Image when saving out to disk

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);        
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜