Why save a .jpeg file using a writetofile file using the UIImageJPEGRepresentation method are large, then UIImageWriteToSavedPhotosAlbum in ios

I am trying to save a UIImage object in a .jpeg file on a device and I use 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 the .jpeg type, but it will take up too much memory compared to the UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil) method UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil) , which saves the same image object in the .jpeg type and the same quality.

My question is why so .. ??

+5
source share
1 answer

You set the quality to really high (1.0), I think 0.6 or 0.7 would be more than enough for jpeg files when I read somewhere.

 NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.65); 

Perhaps you can find the right quality depending on the use of your application, for me sometimes 0.5 is more than enough.

-1
source

Source: https://habr.com/ru/post/1240422/


All Articles