开发者

saving UIImage to file cost a lot of time

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 Photo开发者_开发问答s 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];
  1. the above code(saving 6.4MB image to file) costs about 1.6seconds, is it normal? is there anyway to make it faster?


Try with PNG representation of the image.

NSData *data1 = UIImagePNGRepresentation(image1);

or else reduce the image quality or JPG.

NSData *data1 = UIImageJPEGRepresentation(image1, 0.5);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜