ALAsset缩略图有黑色背景

问题描述:

我已经使用ALAssetsLibrary类编写了自己的图像选择器类。ALAsset缩略图有黑色背景

几乎一切都很好,但有一些图像缩略图具有黑色背景,而实际图像是透明/ alpha通道。

如何解决此问题?

这是我列举块我已经加载从ALAsset缩略图特性,进行图像:

[reversedItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) { 
     UIImage *image = [UIImage imageWithCGImage:[[_assets objectAtIndex:allItems - idx] thumbnail]]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 
      GridView *gridView = (GridView *)obj; 
      gridView.imageView.image = image; 
     }); 
    }); 

}]; 
+0

有同样的问题,但要尽量iOS设备上启动应用程序,设备上,你不应该看到黑色的背景,好像它仅出现在模拟器 – 2013-04-10 16:13:13

+0

其实我看到设备的背景。 – h4cky 2013-04-11 09:00:51

+1

查看模拟器文件系统并查找缩略图,查看保存的格式。据我所知,它是jpeg或其他不支持alpha通道的格式。我知道一个事实,专辑列表中的缩略图是tiff,没有alpha通道。 – TheBlack 2013-04-19 22:53:39

有一个解决办法,如果你使用fullScreenImage属性,它应该是执行较慢,但它应该工作精细。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) { 
     ALAsset *asset = [_assets objectAtIndex:allItems - idx]; 
     UIImage *smallImage = [UIImage imageWithCGImage:[asset thumbnail]]; 
     UIImage *image; 

     CGSize size = [smallImage size]; 
     CGRect box = CGRectMake(0, 0, size.width, size.height); 


     UIGraphicsBeginImageContext(size); 
     CGContextRef context = UIGraphicsGetCurrentContext(); 

     CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]); 
     CGContextFillRect(context, box); 

     CGContextTranslateCTM(context, 0.0, size.height); 
     CGContextScaleCTM(context, 1.0, -1.0); 

     CGContextDrawImage(context, box, [[asset defaultRepresentation] fullScreenImage]); 

     image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 


     dispatch_async(dispatch_get_main_queue(), ^{ 
      TTGridView *gridView = (TTGridView *)obj; 
      gridView.imageView.image = image; 
     }); 
    }); 
+0

是的,它可以工作,但对于生产目的来说非常慢。 – h4cky 2013-04-26 11:31:16