I'm trying to use CGImageSourceCreateThumbnailAtIndex
to efficiently create a resized version of an image. I have some existing code that does this with images from disk, and now I'm trying to use an image that comes from ALAssetsLibrary
.
Here's my code:
ALAsset *asset;
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef imageRef = [representation fullResolutionImage];
CGDataProviderRef provider = CGImageGetDataProvider(imageRef);
CGImageSourceRef sourceRef = CGImageSourceCreateWithDataProvider(provider, NULL);
NSDictionary *resizeOptions = @{
kCGImageSourceCreateThumbnailWithTransform : @YES,
kCGImageSourceCreateThumbnailFromImageAlways : @YES,
kCGImageSourceThumbnailMaxPixelSize : @(2100)
};
CGImageRef resizedImage = CGImageSourceCreateThumbnailAtIndex(source, 0, resizeOptions);
The problem is that resizedImage
is null, and CGImageSourceGetCount(sourceRef)
returns 0. The data provider does have quite a bit of data in it, though, and the data does appear to be valid image data. The ALAsset
comes from an iPhone 4S camera roll.
What am I missing? Why does CGImageSourceCreateWithDataProvider()
create an image source with 0 images?