![]()
请,我不想使用任何其他方法来创建缩略图,只使用CGImageSourceCreatethumbnailAtIndex,因为我想将其性能与我已有的其他方法进行比较.
说,这是我到目前为止的代码.
我用这段代码创建了一个UIImage类:
- (UIImage *)createSquaredthumbnailWithWIDth:(NSInteger)wIDth { CFDictionaryRef options = (__brIDge CFDictionaryRef) @{ (ID) kCGImageSourceCreatethumbnailWithtransform : @YES,(ID) kCGImageSourceCreatethumbnailFromImageAlways : @YES,(ID) kCGImageSourcethumbnailMaxPixelSize : @(wIDth) }; CGImageRef scaledImageRef = CGImageSourceCreatethumbnailAtIndex(????,options); UIImage* scaled = [UIImage imageWithCGImage:scaledImageRef]; CGImageRelease(scaledImageRef); return scaled;} 我的问题在于这一行:
CGImageRef scaledImageRef = CGImageSourceCreatethumbnailAtIndex(????,options);
这个函数的第一个参数需要一个CGImageSourceRef,但就像我说的,我只有一个UIImage,该图像在内存上,而不在磁盘上,我不想将它保存到磁盘上,或者性能会下降到排水.
如何从内存中的UIImage获取CGImageSourceRef?
解决方法 您是否尝试使用CGImageSourceCreateWithData并将图像数据作为CFDataRef传递.NSData *imageData = UIImagePNGRepresentation(image);CGImageSourceRef src = CGImageSourceCreateWithData((__brIDge CFDataRef)imageData,NulL);CFDictionaryRef options = (__brIDge CFDictionaryRef) @{ (ID) kCGImageSourceCreatethumbnailWithtransform : @YES,(ID) kCGImageSourcethumbnailMaxPixelSize : @(wIDth) };CGImageRef scaledImageRef = CGImageSourceCreatethumbnailAtIndex(src,options);UIImage *scaled = [UIImage imageWithCGImage:scaledImageRef];CGImageRelease(scaledImageRef);return scaled; 注意:如果您有图像的URL,则可以使用CGImageSourceCreateWithURL创建CGImageSourceRef.
CGImageSourceRef src = CGImageSourceCreateWithURL((__brIDge CFURLRef)(imagefileURL),NulL);总结
以上是内存溢出为你收集整理的ios – 使用CGImageSourceCreateThumbnailAtIndex从UIImage创建缩略图全部内容,希望文章能够帮你解决ios – 使用CGImageSourceCreateThumbnailAtIndex从UIImage创建缩略图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)