Flip the Image when saving out to disk

与世无争的帅哥 提交于 2019-12-25 02:47:20

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/3632702/flip-the-image-when-saving-out-to-disk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!