为什么.jpeg文件使用UIImageJPEGRepresentation方法通过writetofile保存大尺寸然后在ios中使用UIImageWriteToSavedPhotosAlbum
我试图将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; } }
它将保存.jpeg类型的图像,但与UIImageWriteToSavedPhotosAlbum(mimage,nil,nil,nil)
方法相比需要占用太多内存,该方法以.jpeg类型和相同质量保存相同的图像对象。
我的问题是为什么这样.. ??
你将质量设置得非常高(1.0),我想当我读到某处时,0.6或0.7对于jpeg文件来说已经足够了。
NSData *dataForJPEGFile = UIImageJPEGRepresentation(mimage, 0.65);
也许你可以找到适当的质量取决于你的应用程序使用,对我来说有时0.5绰绰有余。