UIImagePickerControllerOriginalImage vs original asset data
Asked Answered
O

1

8

In the app that I am developing, I am using an image that a user chooses from their photo albums. I need to upload a hi-res version of that photo to my server.

I'm using imagePickerController and I've determined that I have 2 options

  • use UIImage from UIImagePickerControllerOriginalImage
  • get original asset by using UIImagePickerControllerReferenceURL and ALAssetsLibrary assetForURL (I don't like this because it prompts the user to use their current location, which I don't need)

My question is... Is there any difference in the quality of the image if I use the first option vs the second?

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    //option 1
            UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
            NSData *imgData = UIImagePNGRepresentation(image);

    // option 2 (will prompt user to allow use of current location)
            NSURL *imgURL = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
            __block NSData* imgData;

            ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];

            [assetLibrary assetForURL:img resultBlock:^(ALAsset *asset)
             {
                 ALAssetRepresentation *rep = [asset defaultRepresentation];
                 Byte *buffer = (Byte*)malloc(rep.size);
                 NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
                 imgData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; 
             }
                       failureBlock:^(NSError *err) {
                             NSLog(@"Error: %@",[err localizedDescription]);
                         }]; 
        }
Orose answered 10/9, 2012 at 16:15 Comment(1)
I am using option 2 without location permission and it is able to get that one image. (I still cannot use ALAssetsLibrary to access the entire library.) This is working on iOS 5 and iOS 6.Civies
O
13

I ran a test comparing images using both options. Using option 1, the image was twice as big (4.22 MB vs 2.04 MB). Looking at the photos in Photoshop, there didn't seem to be any major difference in quality. When looking at the levels, the one created by option 1 was not as smooth (Image below). when looking at the files properties, the one created by option 1 was missing some "origin", "camera", and "advanced photo" options that the file created by option 2 had. I haven't decided which way I am going to use but hopefully this info will help someone else!

levels in Photoshop

Orose answered 19/9, 2012 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.