UIImagePickerControllerOriginalImage与原始资产数据 [英] UIImagePickerControllerOriginalImage vs original asset data

查看:249
本文介绍了UIImagePickerControllerOriginalImage与原始资产数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在开发的应用中,我使用的是用户从相册中选择的图像。我需要将该照片的高分辨率版本上传到我的服务器。

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.

我正在使用imagePickerController而且我已经确定我有2个选项

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


  • 使用来自UIImagePickerControllerOriginalImage的UIImage

  • 使用UIImagePickerControllerReferenceURL获取原始资产和
    ALAssetsLibrary assetForURL(我不喜欢这样,因为它提示
    用户使用他们的当前位置,我不需要)

我的问题是...... 质量是否有任何差异如果我使用第一个选项vs第二个选项?图像?

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,图像是两倍大(4.22 MB对2.04 MB)。在Photoshop中查看照片,质量似乎没有任何重大差异。查看级别时,选项1创建的级别不是那么平滑(下图)。当查看文件属性时,由选项1创建的属性缺少一些由选项2创建的文件的origin,camera和advanced photo选项。我还没有决定使用哪种方式,但希望这些信息可以帮助其他人!

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!

这篇关于UIImagePickerControllerOriginalImage与原始资产数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆