Note that there are some explanatory texts on larger screens.

plurals
  1. POCGImageSourceCreateThumbnailAtIndex crashes with 20MB Image
    text
    copied!<p>The following method for creating a thumbnail image crashes on an iPad when I test it with large images (ie > 10 MB). I've profiled it and Allocations doesn't report any large memory spikes - it stays consistently at 5 MB of living memory during the operation.</p> <p>How can I create a thumbnail for an image so large? I've tried scaling it with Core Graphics but that is less memory efficient and doesn't work.</p> <pre><code>+(UIImage*) thumbnailImageAtPath:(NSString*) path withSize:(CGSize) size{ @autoreleasepool{ CGImageSourceRef src = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:path], NULL); if(!src){ return nil; } NSDictionary* options = @{ (id)kCGImageSourceShouldAllowFloat : (id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailWithTransform : (id)kCFBooleanFalse, (id)kCGImageSourceCreateThumbnailFromImageIfAbsent : (id)kCFBooleanTrue, (id)kCGImageSourceThumbnailMaxPixelSize : [NSNumber numberWithDouble:1024] }; CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(src, 0, (__bridge CFDictionaryRef)options); // Doesn't reach here :( UIImage* img = [[UIImage alloc] initWithCGImage:thumbnail]; NSLog(@"Size: %f, %f", size.width, size.height); CGImageRelease(thumbnail); CFRelease(src); return img; } } </code></pre> <p>I've tried it on the main thread, worker threads, concurrently, non-concurrently, etc - it just doesn't seem to work on an actual device.</p> <p>What's also strange is that it works brilliantly with a PDF of > 60 MB.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload