【问题标题】:Flip the Image when saving out to disk保存到磁盘时翻转图像
【发布时间】:2010-09-03 02:28:41
【问题描述】:

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

CGImageRef image = CGBitmapContextCreateImage(context);
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *data = UIImagePNGRepresentation(myImage);
[data writeToFile:path atomically:YES];

我发现生成的文件的方向与它在屏幕上的显示方式(在 iPhone 上)相反。保存时翻转此图像的最佳方法是什么,以便稍后加载图像时它会正确显示?

【问题讨论】:

    标签: iphone cocoa-touch uikit core-graphics


    【解决方案1】:

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

    CGContextTranslateCTM(context, 0, height);
    CGContextScaleCTM(context, 1.0, -1.0);        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2011-02-12
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多