2011-12-02 49 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];

和您的縮略圖看起來更好!