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:
我正在尝试在iPhone Photos app中加载图片,然后使用ALAssetsLibrary将选定的图片保存到我的app文件夹中,有两个问题: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];
- the above code(saving 6.4MB image to file) costs about 1.6seconds, is it normal? is there anyway to make it faster?
- 上面的代码(保存6.4MB图像到文件中)大约需要1.6秒,是正常的吗?有什么方法可以让它更快吗?
1 个解决方案
#1
3
Try with PNG representation of the image.
尝试用PNG表示图像。
NSData *data1 = UIImagePNGRepresentation(image1);
or else reduce the image quality or JPG.
或者降低图像质量或JPG格式。
NSData *data1 = UIImageJPEGRepresentation(image1, 0.5);
#1
3
Try with PNG representation of the image.
尝试用PNG表示图像。
NSData *data1 = UIImagePNGRepresentation(image1);
or else reduce the image quality or JPG.
或者降低图像质量或JPG格式。
NSData *data1 = UIImageJPEGRepresentation(image1, 0.5);