1

I am creating an app which lets the user select a image from the photo library using UIImagePickerController and then saves the image using ALAssets Library. But there is a difference between the quality and size of the image being saved by my app. compared to the original image which was picked from the photo library.

I added logging to check the size of the image being picked and the image saved in photo library using ALAsset library.

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   UIImage *image = [info
                     objectForKey:UIImagePickerControllerOriginalImage];
   NSLog(@"Size of the image picked in bytes: %i",[UIImageJPEGRepresentation(image,1.0f) length]);
}

-(void)methodToSaveImage:(UIImage*)image metadata:(NSMutableDictionary*)info
{
    @autoreleasepool {
        NSLog(@"Size of image passed to be saved: %i",[UIImageJPEGRepresentation(image,1.0f) length]);
        [self writeImageToSavedPhotosAlbum:image.CGImage metadata:info
                           completionBlock:^(NSURL* assetURL, NSError* error) {

                               //error handling
                               if (error!=nil) {
                                   return;
                               }
                               ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
                               {
                                   NSLog(@"Size of image after being saved in photo library : %i",[myasset defaultRepresentation].size);
                               };

                               //
                               ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror)
                               {
                                   NSLog(@"cant get image - %@",[myerror localizedDescription]);
                               };

                               [self assetForURL:assetURL
                                    resultBlock:resultblock
                                    failureBlock:failureblock];


        }];
    }
}

The size in bytes of the images when picked and passed to be saved is equal and approximately 4 MB. But the size of the image saved in the photo library is only a little more than 2 MB. Please let me know why is there a difference in the image? And what can I do to save the image with exact size as of the original image?

TGiri
  • 131
  • 6

1 Answers1

0

same Ans I'm Also searching. But if You wat to generate checksums of both the images (before write and after write). Then use:

NSData* data =  UIImageJPEGRepresentation(copyOfOriginalImage, 1);
NSLog(@"The Read Image MD5: %@",[data MD5]);

Checsum will remains same. But still size difference is there.

iDevAmit
  • 1,550
  • 2
  • 21
  • 33