1

I am binding the photo Library images to my Table-view using ALAsset Library. So whenever i am binding the ALAsset Thumbnail image as a TableView cell image, there is a issue with image Clarity.It Shows as a low clarity image. I have Created a full resolution image from AlAsset and wrote the thumbnail generation method, i have set the resultant image as table-view image. After done the above process, i got the full resolution image thumbnail on Table-view. But the issue was the performance with first time table View image bind process(i used a cache to bind the image after bind first time.So the performance will fast after first time).

So May i know, How can i get the Photo-library full clarity thumbnail image from ALAsset?

I have wrote the below code in MyTableView CellForRowIndexPath is


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...

I have tried the below method which is time consuming


 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;
}

Thanks.

beryllium
  • 29,669
  • 15
  • 106
  • 125
adrian
  • 4,574
  • 17
  • 68
  • 119

3 Answers3

0

You should also try [rep fullScreenImage] for a better performant table view but an image with better quality than thumbnail.

jarora
  • 5,384
  • 2
  • 34
  • 46
0

You can use

CGImageRef iref = [myasset aspectRatioThumbnail];

and your thumbnail look much better !

Max
  • 774
  • 7
  • 20
0

i don't think there is much you can do here.. as those are the only two options we have from ALAsset. you will have to compromise either on quality or time. If you are using the images that you have yourself stored in the library then you can re size them before storing to be a bit smaller to increase the speed of the process.

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115