UIImage 的高质量缩放
我需要缩放来自 iPhone 应用程序中视图层的图像的分辨率。显而易见的方法是在 UIGraphicsBeginImageContextWithOptions 中指定比例因子,但只要比例因子不是 1.0,图像质量就会受到影响——远远超出像素损失的预期。
我尝试过其他几种缩放技术,但它们似乎都围绕 CGContext 的东西,并且似乎都做同样的事情。
仅仅改变图像“大小”(不改变点分辨率)是不够的,主要是因为该信息似乎很快就被管道中的其他人丢弃(图像将被转换为 JPG 并通过电子邮件发送)。
iPhone 上还有其他缩放图像的方法吗?
I need to scale the resolution of an image coming from a view layer in an iPhone application. The obvious way is to specify a scale factor in UIGraphicsBeginImageContextWithOptions, but any time the scale factor is not 1.0 then quality of the image goes to pot -- far more than would be expected from the loss of pixels.
I've tried several other scaling techniques, but they all seem to revolve around CGContext stuff and all appear to do the same thing.
Simply changing image "size" (without changing the dot resolution) isn't sufficient, mostly because that info seems to be discarded very quickly by other hands in the pipeline (the image will be converted to a JPG and emailed).
Is there any other way to scale an image on iPhone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Swift 扩展:
示例:
如果图像没有 alpha,则将 isOpaque 设置为 true:绘图将具有更好的性能。
Swift extension:
Example:
Set isOpaque to true if the image has no alpha: drawing will have better performance.
关于UIImage调整大小问题,这篇文章< /a> 提供了多种处理 UIImage 对象的方法。 UIImage 有一些方向问题需要修复。 这个和另一篇文章将解决这个问题。
About UIImage resize problem, this post give many ways to handle UIImage object. The UIImage has some orientation problems need to be fixed. This and Another post will address it.
我想出了这个算法来创建半尺寸图像:
我尝试只取每隔一行的每个像素,而不是取平均值,但它产生的图像与默认算法一样糟糕。
I came up with this algorithm to create a half-size image:
I tried just taking every other pixel of every other row, instead of averaging, but it resulted in an image about as bad as the default algorithm.
我想你可以使用类似 imagemagick 的东西。显然它已经成功移植到iPhone: http://www.imagemagick.org /discourse-server/viewtopic.php?t=14089
我一直对此库缩放的图像质量感到满意,所以我认为您会对结果感到满意。
I suppose you could use something like imagemagick. Apparently it's been successfully ported to iPhone: http://www.imagemagick.org/discourse-server/viewtopic.php?t=14089
I've always been satisfied with the quality of images scaled by this library, so I think you'll be satisfied with the result.