我想使用CG創建縮略圖。它創建縮略圖。CGImage創建想要的大小的縮略圖
這裏我想要縮略圖的大小爲1024(帶縱橫比)。是否可以直接從CG中獲得想要的大小縮略圖?
在選項字典我可以通過thumnail的最大尺寸可以創建,但有沒有什麼辦法讓最小尺寸相同..?
NSURL * url = [NSURL fileURLWithPath:inPath];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef image=nil;
if (source)
{
NSDictionary* thumbOpts = [NSDictionary dictionaryWithObjectsAndKeys:
(id) kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailWithTransform,
(id)kCFBooleanTrue, (id)kCGImageSourceCreateThumbnailFromImageIfAbsent,
[NSNumber numberWithInt:2048], kCGImageSourceThumbnailMaxPixelSize,
nil];
image = CGImageSourceCreateThumbnailAtIndex(source, 0, (CFDictionaryRef)thumbOpts);
NSLog(@"image width = %d %d", CGImageGetWidth(image), CGImageGetHeight(image));
CFRelease(source);
}