不使用UIImagePickerControllerOriginalImage获取相册图片

 
 

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

 

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

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

 

  1. ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
  2.      [library assetForURL:[dic objectForKey:UIImagePickerControllerReferenceURL]  
  3.               resultBlock:^(ALAsset *asset)  
  4.       {  
  5.           ALAssetRepresentation *representation = [asset defaultRepresentation];  
  6.           CGImageRef imgRef = [representation fullResolutionImage];  
  7.           UIImage *image = [UIImage imageWithCGImage:imgRef  
  8.                                              scale:representation.scale  
  9.                                        orientation:(UIImageOrientation)representation.orientation];  
  10.           NSData * data = UIImageJPEGRepresentation(image, 0.5);                  
  11.   
  12.       }failureBlock:^(NSError *error){  
  13.           NSLog(@"couldn't get asset: %@", error);  
  14.       }  
  15.       ];  
posted @ 2015-05-07 11:31  Allen.Ma  阅读(840)  评论(0编辑  收藏  举报