One of the ways I found the sketch was to specify kCGImageSourceCreateThumbnailFromImageIfAbsent in the settings dictionary.
Specify the dictionary as follows
NSDictionary* thumbOpts = [NSDictionary dictionaryWithObjectsAndKeys: (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailFromImageIfAbsent, (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailWithTransform, [NSNumber numberWithInt:128], (id)kCGImageSourceThumbnailMaxPixelSize, nil];
Update. To add a secondary (thumbnail) image to the original CGImageDestinationRef, do the following after adding the main image
size_t thumbWidth = 640; size_t thumbHeight = imageHeight / (imageWidth / thumbWidth); size_t thumbBytesPerRow = thumbWidth * 4; size_t thumbTotalBytes = thumbBytesPerRow * thumbHeight; void *thumbData = malloc(thumbTotalBytes); CGContextRef thumbContext = CGBitmapContextCreate(thumbData, thumbWidth, thumbHeight, 8, thumbBytesPerRow, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst); CGRect thumbRect = CGRectMake(0.f, 0.f, thumbWidth, thumbHeight); CGContextDrawImage(thumbContext, thumbRect, fullImage); CGImageRef thumbImage = CGBitmapContextCreateImage(thumbContext); CGContextRelease(thumbContext); CGImageDestinationAddImage(destination, thumbImage, nil); CGImageRelease(thumbImage);
Then, to return the sketch, follow these steps
CFURLRef imageFileURLRef = (__bridge CFURLRef)url; NSDictionary* sourceOptions = @{(id)kCGImageSourceShouldCache: (id)kCFBooleanFalse, (id)kCGImageSourceTypeIdentifierHint: (id)kUTTypeTIFF}; CFDictionaryRef sourceOptionsRef = (__bridge CFDictionaryRef)sourceOptions; CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imageFileURLRef, sourceOptionsRef); CGImageRef thumb = CGImageSourceCreateImageAtIndex(imageSource, 1, sourceOptionsRef); UIImage *thumbImage = [[UIImage alloc] initWithCGImage:thumb]; CFRelease(imageSource); CGImageRelease(thumb);