I’m trying to create an aspect ratio thumbnail from an ALAsset for pre iOS5 (the ALAssetDefaultRepresentation aspectRatioThumbnail wasn’t implemented until ios5). I have the following code and it’s giving me an error for some reason:
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);
Specifically I’m getting:
ImageIO: <ERROR> CGImageSourceCreateWithURL CFURLCreateDataAndPropertiesFromResource failed with error code -11.ImageIO: <ERROR> CGImageSourceCreateThumbnailAtIndex image source parameter is nil
Anyone know what’s going on?
The problem is with the
urlthat you are passing to create ‘src‘,check wether
urlis valid and there exists some image at this url.