zoukankan      html  css  js  c++  java
  • 不使用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.       ];  
  • 相关阅读:
    Id vs Instancetype
    【转】为什么要走出你的心理“舒适区”
    【转】深入浅出 iOS 之生命周期
    【转】Objective-C类初始化:load与initialize
    【转】Cocoapod 的安装和使用
    非对称加密回顾
    iOS中 Proxy和的delegate区别
    IOS 对JSON解析的要求
    内存对齐规则
    KVO 的进一步理解
  • 原文地址:https://www.cnblogs.com/allen123/p/4484333.html
Copyright © 2011-2022 走看看