首页 > 选取相片后assets-library的转化

选取相片后assets-library的转化

再选取相片后得到下面的信息

ALAsset - Type:Photo, URLs:assets-library://asset/asset.JPG?id=9C5EF6C3-0E1C-4F05-B592-CED2203EFE0F&ext=JPG

如何把这个信息转化成一个uiimage对象


assets-library 是UIImagePickerController方法中一个返回字典的值,一般是
info[UIImagePickerControllerReferenceURL] 得到的就是assets-library的地址


多加一句,如何通过asset url 获取 alasset。

 ALAssetsLibrary   *lib = [[ALAssetsLibrary alloc] init];  
[lib assetForURL:[NSURL URLWithString:assetUrl] resultBlock:^(ALAsset *asset)
{
//在这里使用asset来获取图片
}
failureBlock:^(NSError *error) 
{}
];

Asset URL不能转化为image。当用ALAsset获取

+ (UIImage *)fullResolutionImageFromALAsset:(ALAsset *)asset
{
    ALAssetRepresentation *assetRep = [asset defaultRepresentation];
    CGImageRef imgRef = [assetRep fullResolutionImage];
    UIImage *img = [UIImage imageWithCGImage:imgRef
                                       scale:assetRep.scale
                                 orientation:(UIImageOrientation)assetRep.orientation];
    return img;
}

另使用此库需注意,iOS4、5需向用户申请GPS权限才可访问照片。iOS6下申请相册访问权限才可访问照片。

【热门文章】
【热门文章】