Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 设置缩略图的背景为黑色_Objective C_Alassetslibrary_Alasset - Fatal编程技术网

Objective c 设置缩略图的背景为黑色

Objective c 设置缩略图的背景为黑色,objective-c,alassetslibrary,alasset,Objective C,Alassetslibrary,Alasset,我使用ALAssetsLibrary类编写了自己的图像选择器类 几乎一切都很好,但是有些图像缩略图有黑色背景,而实际图像是透明的/alpha通道。 如何解决这个问题 这是我的枚举块,我在其中从ALAsset缩略图属性加载了图像: [reversedItems enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { dispatch_async(dispatch_get_global_queue(DISPATC

我使用
ALAssetsLibrary
类编写了自己的图像选择器类

几乎一切都很好,但是有些图像缩略图有黑色背景,而实际图像是透明的/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;
        });
    });

}];

如果使用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;
        });
    });

也有同样的问题,但尝试在ios设备上启动应用程序,在设备上你不应该看到黑色背景,似乎它只出现在模拟器中。实际上,我在设备上看到了背景。查看模拟器文件系统并找到缩略图,查看它们保存的格式。据我记忆所及,它是jpeg或其他一些不支持alpha通道的格式。我知道专辑列表中的缩略图是tiff,并且没有alpha通道;第二,即使我在模拟器上测试在哪里可以找到这些缩略图。