不使用UIImagePickerControllerOriginalImage获取相册图片

来源:互联网 发布:ubuntu 怎么进入u盘 编辑:程序博客网 时间:2024/04/30 03:44

m

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

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

来获取原图,但是我使用这个方法获取到得图片并不是原图,而是尺寸经过压缩后的,后来找到了一个新的方法来进行获取 直接贴代码
[cpp] view plaincopy
  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.       ]; 

0 0
原创粉丝点击