将 UIImage 保存到文件会花费大量时间
我尝试在 iPhone 照片应用程序中加载图片,然后使用 ALAssetsLibrary 将所选图片保存到我的应用程序文件夹中,但有两个问题: 1. 保存到磁盘的图像文件比照片应用程序中的原始文件大得多,例如,一张图片是2.8MB,但保存到我的应用程序文件夹后,它是6.4MB,以下是代码:
CGImageRef cgImage = [localPhoto thumbnail];
NSString *path = @"/documents/test/1.jpeg";//the path is just an example
BOOL succ;
UIImage *image1 = [UIImage imageWithCGImage:cgImage];
NSData *data1 = UIImageJPEGRepresentation(image1, 1.0);
succ = [data1 writeToFile:path atomically:YES];
- 上面的代码(节省6.4) MB图像到文件)大约需要1.6秒,正常吗?有什么办法可以让它更快吗?
I'm trying to load pictures in iPhone Photos app, then save the selected pictures in to my app's folder, using ALAssetsLibrary, and have two issues:
1. the image file saved to disk is much bigger then original files in Photos app, for example, a picture is 2.8MB, but after saved to my app's folder, it's 6.4MB, following is the code:
CGImageRef cgImage = [localPhoto thumbnail];
NSString *path = @"/documents/test/1.jpeg";//the path is just an example
BOOL succ;
UIImage *image1 = [UIImage imageWithCGImage:cgImage];
NSData *data1 = UIImageJPEGRepresentation(image1, 1.0);
succ = [data1 writeToFile:path atomically:YES];
- the above code(saving 6.4MB image to file) costs about 1.6seconds, is it normal? is there anyway to make it faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 PNG 表示图像。
或者降低图像质量或 JPG。
Try with PNG representation of the image.
or else reduce the image quality or JPG.