I want to use the function CGImageSourceCreateThumbnailAtIndex to create a thumbnail from an UIImage. All I have is the UIImage itself. Th
Have you try using CGImageSourceCreateWithData and passing image data as CFDataRef like this.
NSData *imageData = UIImagePNGRepresentation(image);
CGImageSourceRef src = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
CFDictionaryRef options = (__bridge CFDictionaryRef) @{
(id) kCGImageSourceCreateThumbnailWithTransform : @YES,
(id) kCGImageSourceCreateThumbnailFromImageAlways : @YES,
(id) kCGImageSourceThumbnailMaxPixelSize : @(width)
};
CGImageRef scaledImageRef = CGImageSourceCreateThumbnailAtIndex(src, 0, options);
UIImage *scaled = [UIImage imageWithCGImage:scaledImageRef];
CGImageRelease(scaledImageRef);
return scaled;
Note: If you have URL of image then you can create CGImageSourceRef using CGImageSourceCreateWithURL.
CGImageSourceRef src = CGImageSourceCreateWithURL((__bridge CFURLRef)(imageFileURL), NULL);