Saving UIImage to a file costs a lot of time

I try to upload images in the iPhone Photos application, then save the selected images in the folder with my application using ALAssetsLibrary, and you have two problems: 1. The image file saved on disk is much larger than the source files in the Photos application For example, the image is 2.8 MB, but after saving to my application folder it is 6.4 MB, the following 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.4 MB image to file) costs about 1.6 seconds, is this normal? is there any way to make it faster?
+3
source share
1 answer

Try the PNG representation of the image.

NSData *data1 = UIImagePNGRepresentation(image1);

JPG.

NSData *data1 = UIImageJPEGRepresentation(image1, 0.5);
+3

Source: https://habr.com/ru/post/1763991/


All Articles