我正在使用 ALAsset 库将照片库图像绑定到我的表视图。因此,每当我将 ALAsset 缩略图图像绑定为 TableView 单元格图像时,图像清晰度就会出现问题。它显示为低清晰度图像。我从 AlAsset 创建了一个全分辨率图像并编写了缩略图生成方法,我将生成的图像设置为表格视图图像。完成上述过程后,我在 Table-view 上获得了全分辨率图像缩略图。但问题是第一次时间表查看图像绑定过程的性能(我在第一次绑定后使用缓存来绑定图像。所以第一次后性能会很快)。
所以我可以知道,我怎样才能从 ALAsset 获得照片库全清晰度缩略图?
我在 MyTableView CellForRowIndexPath 中编写了以下代码是
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
CGImageRef iref = [myasset thumbnail];
if (iref) {
importMediaSaveImage.image = [UIImage imageWithCGImage:iref];
}
etc...
我尝试了以下方法,这很耗时
UIImageView *importMediaSaveImage=[[[UIImageView alloc] init] autorelease];
importMediaSaveImage.frame=CGRectMake(0, 0, 200,135 );
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImage *images;
if (iref) {
images = [UIImage imageWithCGImage:iref];
}
NSData *data = [self photolibImageThumbNailData:images];
importMediaSaveImage.image = [UIImage imageWithData:data];
etc....
photolibImageThumbNailData
-(NSData *)photolibImageThumbNailData:(UIImage *)image{
// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(200.0,135.0));
// now redraw our image in a smaller rectangle.
[image drawInRect:CGRectMake(0.0, 0.0, 200.0, 135.0)];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now grab the PNG representation of our image
NSData *thumbData = UIImagePNGRepresentation(newImage);
return thumbData;
}
谢谢。