I have a UIImageView and would like to set it to the contents of an ALAsset.
How is开发者_StackOverflow中文版 the ALAssets contents used to set a UIImage?
Try this. Asset is ALAsset by the way.
UIImage *image = [UIImage imageWithCGImage:[asset thumbnail] scale:1.0 orientation:[[asset defaultRepresentation] orientation]]
UIImageView *image_view = [[UIImageView alloc] initWithImage:image]
As mentioned by Clayton and Aaron Brager, the key is imageWithCGImage method of UIImage class.
There are a two ways to get image content:
- asset.thumbnail or asset.aspectThumbnail
- via a presentation of the asset
- there are default presentation and presentation for UTI
- CGImage prepared
- CGImageWithOptions, fullResolutionImage, fullScreenImage
- raw data
- getBytes:fromOffset:length:error:
- (if you want to keep EXIF etc, use imageWithData instead of imageWithCGImage)
You may refer http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetRepresentation_Class/Reference/Reference.html#//apple_ref/doc/c_ref/ALAssetRepresentation for more details.
ALAssetRepresentation *rep = [self defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[rep fullScreenImage]];
精彩评论