从UIImage创建缩略图我想使用函数CGImageSourceCreateThumbnailAtIndex
从UIImage
创建缩略图。我所拥有的是UIImage
本身。该图片是UIView
上的快照。使用CGImageSourceCreateThumbnailAtIndex
请不要使用任何其他方法创建缩略图,只是使用CGImageSourceCreateThumbnailAtIndex
的缩略图,因为我想将其性能与其他已有方法进行比较。
说,这是我迄今的代码。
我已创建一个UIImage
类与此代码:
- (UIImage *)createSquaredThumbnailWithWidth:(NSInteger)width {
CFDictionaryRef options = (__bridge CFDictionaryRef) @{
(id) kCGImageSourceCreateThumbnailWithTransform : @YES,
(id) kCGImageSourceCreateThumbnailFromImageAlways : @YES,
(id) kCGImageSourceThumbnailMaxPixelSize : @(width)
};
CGImageRef scaledImageRef = CGImageSourceCreateThumbnailAtIndex(????, 0, options);
UIImage* scaled = [UIImage imageWithCGImage:scaledImageRef];
CGImageRelease(scaledImageRef);
return scaled;
}
我的问题是这一行:
CGImageRef scaledImageRef = CGImageSourceCreateThumbnailAtIndex(????, 0, options);
这个函数的第一个参数需要一个CGImageSourceRef
,但就像我说的,我只是有一个UIImage
,该图像是在内存中,而不是在磁盘上,我不想将它保存到磁盘,或性能会下降。
我如何从UIImage
是在内存CGImageSourceRef
???
什么内存?所有图像实例都在内存中。使用它作为@Nirav D说。 –