views:

90

answers:

1

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];
  1. the above code(saving 6.4MB image to file) costs about 1.6seconds, is it normal? is there anyway to make it faster?
A: 

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);
Anil Sivadas
I did it, UIImagePNGRepresentation will generate a much bigger file, more than 10MB, I'll try to decrease the quality.
disorderdev
hoho, something interesting, when I use UIImageJPEGRepresentation(image1, 0.5), the saved file is 1.4MB, this is just half of the original file(2.8MB) size, then I use UIImageJPEGRepresentation(image1, 0.9), the saved file is 3.5MB,:), anyway, it's acceptable, I decided to use 0.9, anyone has better suggestion?
disorderdev