Why .jpeg file save via writetofile using UIImageJPEGRepresentation method have large size then UIImageWriteToSavedPhotosAlbum in ios

夙愿已清 提交于 2019-12-06 00:42:26

问题


I am trying to save an UIImage object to an .jpeg file in device and 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;
    }
}

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:


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

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



来源:https://stackoverflow.com/questions/34740631/why-jpeg-file-save-via-writetofile-using-uiimagejpegrepresentation-method-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!