6

我正在尝试将UIImage对象保存到设备中的 .jpeg 文件中,并且我正在使用以下代码:

-(void)saveImageToDocumentsDirectory:(UIImage *)mimage withFileName:(NSString *)fileName 
{
    UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil);
    NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 1.0);
    NSError *error2 = nil;
    if (![dataForJPEGFile writeToFile:[self getDirectoryFilePath:fileName] options:NSAtomicWrite error:&error2])
    {
        return;
    }
}

UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil)它会保存 .jpeg 类型的图像,但与保存相同图像对象的 .jpeg 类型和相同质量的方法相比占用太多内存。

我的问题是为什么会这样..??

4

1 回答 1

-1

您将质量设置为非常高(1.0),我想当我在某处阅读时,0.6 或 0.7 对于 jpeg 文件来说已经足够了。

NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.65);

也许你可以根据你的应用程序使用找到合适的质量,对我来说,有时 0.5 就足够了。

于 2016-03-07T09:43:00.387 回答