1

我正在使用 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;
}

谢谢。

4

3 回答 3

0

我认为您在这里无能为力。因为这是我们从 ALAsset 获得的仅有的两个选项。您将不得不在质量或时间上做出妥协。如果您使用的是您自己存储在库中的图像,那么您可以在存储之前重新调整它们的大小以提高处理速度。

于 2011-12-02T08:29:29.677 回答
0

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

于 2015-03-24T13:12:38.010 回答
0

您可以使用

CGImageRef iref = [myasset aspectRatioThumbnail];

你的缩略图看起来好多了!

于 2015-10-20T15:37:02.567 回答