尝试从图像I / O创建AspectRatioThumbnail时出错

时间:2012-05-14 20:25:40

标签: iphone ios cocoa-touch core-graphics

我正在尝试为iOS5之前的ALAsset创建宽高比缩略图(直到ios5才会实现ALAssetDefaultRepresentation aspectRatioThumbnail)。我有以下代码,它出于某种原因给我一个错误:

CGImageRef imref;
    NSURL* url = [self.photoAsset.defaultRepresentation url];
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                       (id)kCFBooleanTrue, kCGImageSourceShouldAllowFloat,
                       (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailWithTransform,
                       (id)kCFBooleanTrue, kCGImageSourceCreateThumbnailFromImageAlways,
                       [NSNumber numberWithInteger:1024], kCGImageSourceThumbnailMaxPixelSize, nil];
    CGImageSourceRef src = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
    imref = CGImageSourceCreateThumbnailAtIndex(src, 0, (CFDictionaryRef) dictionary);

具体来说,我得到了:

ImageIO: <ERROR>  CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource failed with error code -11.ImageIO: <ERROR>  CGImageSourceCreateThumbnailAtIndex image source parameter is nil

任何人都知道发生了什么事?

1 个答案:

答案 0 :(得分:1)

问题在于您要传递的url来创建“src”, check wether url有效且此网址上有一些图片。