您的位置:首页 > 产品设计 > UI/UE

不使用UIImagePickerControllerOriginalImage获取相册图片

2015-05-07 11:31 387 查看
 
 

一般用imagePickerController获取到dic以后常用的方法是使用

 

UIImage *image = [dic objectForKey:@"UIImagePickerControllerOriginalImage"];

来获取原图,但是我使用这个方法获取到得图片并不是原图,而是尺寸经过压缩后的,后来找到了一个新的方法来进行获取 直接贴代码
 

[cpp] view plaincopy

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

     [library assetForURL:[dic objectForKey:UIImagePickerControllerReferenceURL]  

              resultBlock:^(ALAsset *asset)  

      {  

          ALAssetRepresentation *representation = [asset defaultRepresentation];  

          CGImageRef imgRef = [representation fullResolutionImage];  

          UIImage *image = [UIImage imageWithCGImage:imgRef  

                                             scale:representation.scale  

                                       orientation:(UIImageOrientation)representation.orientation];  

          NSData * data = UIImageJPEGRepresentation(image, 0.5);                  

  

      }failureBlock:^(NSError *error){  

          NSLog(@"couldn't get asset: %@", error);  

      }  

      ];  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: