Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerControllerOriginalImage vs original asset data

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]);
                         }]; 
        }
like image 502
jessieloo Avatar asked Sep 10 '12 16:09

jessieloo


1 Answers

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

like image 140
jessieloo Avatar answered Nov 09 '22 09:11

jessieloo