1

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?

Ser Pounce
  • 14,196
  • 18
  • 84
  • 169
  • 2
    I've put an answer on this question about how to generate a from an ALAsset: http://stackoverflow.com/questions/11765340/generating-custom-thumbnail-from-alassetrepresentation/13941431#13941431 – Jesse Rusak Dec 18 '12 at 21:08

1 Answers1

1

The problem is with the url that you are passing to create 'src', check wether url is valid and there exists some image at this url.

Ravin
  • 8,544
  • 3
  • 20
  • 19
  • I think the URL I'm retrieving isn't for the image, but for the asset itself. Any idea how to get the image URL? – Ser Pounce May 16 '12 at 00:01