2011-12-02 48 views
1

我使用ALAsset库将照片库图像绑定到我的表视图。 因此,无论何时我将ALAsset缩略图图像作为TableView单元格图像进行绑定,图像清晰度都存在问题。它显示为低清晰度图像。 我已经从AlAsset创建了一个全分辨率的图像,并写了缩略图生成方法,我已将所得图像设置为表视图图像。 完成上述过程后,我在Table-view上获得了全分辨率图像缩略图。 但问题是性能与第一次表查看图像绑定过程(我使用缓存绑定第一次绑定图像。因此,性能将在第一次后快速)。ALAsset的低清晰度缩略图

因此,我可以知道,我如何从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; 
} 

谢谢。

回答

0

我不认为你可以在这里做很多事情,因为这些是ALAsset中唯一的两个选项。你将不得不妥协质量或时间。如果您正在使用您自己存储在库中的图像,则可以在存储之前重新调整它们的大小以缩小处理速度。

0

您还应该尝试[rep fullScreenImage]以获得更好的高性能表格视图,但质量要比缩略图好。

0

您可以使用

CGImageRef iref = [myasset aspectRatioThumbnail];

和您的缩略图看起来更好!