以下效果很好
if let currentImage = CGImageSourceCreateWithData(imageData,nil) //...some code that extracts the existing size,and based on my maximum expected horizontal size..calculates a new horizontal/vertical maximum size.. let options: CFDictionary = [kCGImageSourceThumbnailMaxPixelSize as NSString : maximumImageWidthOrHeight,kCGImageSourceCreateThumbnailFromImageAlways as NSString : true] CGImageSourceCreateThumbnailAtIndex(image,options)
但仅用于下采样.
如果我有一个全高清的图像即1920 x 1080,它被调整大小(保持宽高比),使其适合320 px水平,因为这是我设置为最大水平尺寸.
但是,如果我传递一个16像素×9像素的图像,那么一个很小的图像(并且具有16:9的宽高比).此图像未调整大小.
我想要将其调整为320 x 180像素.
是否有组合的选项/错过的方法调用/任何会给我在imageIO框架中的任何东西?
解决方法
ImageIO旨在逐步加载图像(如Web图像),构建快速缩略图(最大尺寸将是原始图像之一),并构建缓存或不映像的组. Here’s the manual
最简单的方法是使用UIKit,并且将使用范围(0< ratio< 1)中的缩放比例.
for example,to go from a 16×9 image to a 230×180 will be:
let image = UIImage(data: yourImageData!,scale: 0.050)!
还有其他的方法,如NSHipster所描述的,只是稍微复杂一点,但值得一试,并进行一些性能测试来选择哪一个是更好的上采样.但是这取决于你来测试.
无论哪种方式,结果将是非常糟糕的,因为上采样
仍在研究之中,是一项非常困难的任务.
There are several papers on this topic,but they are usually related
to upsampling an specific kind of objects and this allows the
algorithm to make some needed assumptions,for example:
07002If I were to choose a way to achieve this and quality were my goal,I would go for 07003 07004.
But,they are iterative algorithms,so maybe don’t fit your performance needs.
07005
所以,您可能需要重新考虑这对您的应用程序有多重要,也可能会找到解决方法,因为现在无法实现同时兼容的质量和实时性能.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。