本文介绍了为什么.jpeg文件使用UIImageJPEGRepresentation方法通过writetofile保存大尺寸然后在ios中使用UIImageWriteToSavedPhotosAlbum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to save an UIImage object to an .jpeg file in deviceand I am using this code:

-(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;
    }
}

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

It will save the image of .jpeg type but take too much memory as compare to the UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil) method, which saves the same image object in .jpeg type and same quality.

我的问题是为什么...... ??

My question is why so..??

推荐答案

您正在设定质量真的很高(1.0),我想在我读到的地方时,0.6或0.7对于jpeg文件来说已经足够了。

You are setting the quality to be really high (1.0), I guess 0.6 or 0.7 would be more than enough for jpeg files as I read somewhere.

NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.65);

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

Maybe you can find the appropriate quality depending on your app use, for me sometimes 0.5 is more than enough.

这篇关于为什么.jpeg文件使用UIImageJPEGRepresentation方法通过writetofile保存大尺寸然后在ios中使用UIImageWriteToSavedPhotosAlbum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 23:29