UIImagePickerControllerOriginalImage vs original asset data

梦想的初衷 提交于 2019-12-06 22:43:08

问题


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]);
                         }]; 
        }

回答1:


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!



来源:https://stackoverflow.com/questions/12355589/uiimagepickercontrolleroriginalimage-vs-original-asset-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!