保存到磁盘时翻转图像 [英] Flip the Image when saving out to disk

查看:42
本文介绍了保存到磁盘时翻转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用以下代码将CGContext写入磁盘上的PNG:

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

我发现结果文件的方向从它在屏幕上的显示方式翻转了(在iPhone)。在保存时翻转此图像的最佳方法是什么,以便以后加载图像时该图像正确?

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?

推荐答案

UIImage和CG上下文的坐标系相互翻转。您可以在绘制CGContext之前先翻转它:

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

这篇关于保存到磁盘时翻转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆