我使用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;
}
謝謝。