保存非常大的 uiimage 文件

Posted

技术标签:

【中文标题】保存非常大的 uiimage 文件【英文标题】:Saving really big uiimage files 【发布时间】:2013-09-12 06:37:58 【问题描述】:

我制作了一个应用程序,它可以创建由文本组成的非常大的图像(最大的图像大约是 iPhone 屏幕大小的十倍)。我尝试使用UIImageWriteToSavedPhotosAlbum,但它以低得多的分辨率保存。有没有办法以全质量保存图像?

【问题讨论】:

【参考方案1】:

看看NSFileManager。在您的应用程序沙箱中创建一个子目录,您将在其中保存文件(图像)。如果您不希望将图像保存在 ios 相册中并将其私有用于您的应用程序,这当然是相关的。

【讨论】:

【参考方案2】:
- (UIImage *)renderLayerOf:(UIView *)yourView 
     //in this case 'yourView' is the label containing the large text
    UIGraphicsBeginImageContext(yourView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[yourView layer] renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    return image;

此方法会将任何 UIView 转换为 Image。获得图像后,您可以保存使用 NSFileManager。希望对您有所帮助。

【讨论】:

以上是关于保存非常大的 uiimage 文件的主要内容,如果未能解决你的问题,请参考以下文章

在 Core Data 中保存 UIImage 的最佳方法

iOS Swift - 在 UIImage 上画线以保存到文件

如何使用 NSFileManager 将 UIImage 保存到文件中?

Objective C - 将 UIImage 保存为 BMP 文件

UIButton 中像素精确的 UIImage 重采样

UIImage 在 iPhone 上保存带有文件名的图像