Android:使用比双线性更好的重采样算法调整位图大小(如 Lanczos3) [英] Android: Bitmap resizing using better resampling algorithm than bilinear (like Lanczos3)

查看:29
本文介绍了Android:使用比双线性更好的重采样算法调整位图大小(如 Lanczos3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法或外部库可以使用 Lanczos(理想情况下)或至少双三次算法调整图像大小.在 Android 下?(当然越快越好,但质量是首要的,处理时间是次要的)

Is there any way or external library that can resize image using Lanczos (ideally) or at least bicubic alg. under Android? (faster is better of course, but quality is priority, a processing time is secondary)

到目前为止我所拥有的一切是这样的:

Everything what I've got so far is this:

Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);

然而它使用双线性滤波器并且输出质量很差.特别是如果您想保留细节(如细线或可读文本).

However it uses bilinear filter and the output quality is terrible. Especially if you want to preserve details (like thin lines or readable texts).

有许多很好的 Java 库,例如这里讨论的:Java - 在不降低质量的情况下调整图像大小

There are many good libraries for Java as discussed for example here: Java - resize image without losing quality

但是它总是依赖于java.awt.image.BufferedImage之类的Java awt类,所以它不能在Android中使用.

However it's always depended on Java awt classes like java.awt.image.BufferedImage, so it can't be used in Android.

有没有办法在 Bitmap.createScaledBitmap() 方法或诸如 Morten Nobel 的库 能够与 android.graphics.Bitmap 类一起使用(或使用一些原始表示,如评论中的 @Tron已经指出)?

Is there a way how to change the default (bilinear) filter in Bitmap.createScaledBitmap() method or some library like Morten Nobel's lib that is able to work with android.graphics.Bitmap class (or with some raw representation, as @Tron in the comment has pointed out)?

推荐答案

最有前途的 IMO 是使用 libswscale(来自 FFmpeg),它提供 Lanczos 和许多其他过滤器.要从本机代码访问 Bitmap 缓冲区,您可以使用 jnigraphics.这种方法保证了良好的性能和可靠的结果.

The most promising IMO is to use libswscale (from FFmpeg), it offers Lanczos and many other filters. To access Bitmap buffer from native code you can use jnigraphics. This approach guarantees nice performance and reliable results.

编辑

这里 你可以找到粗略的演示应用程序,它使用了建议的方法.目前性能非常糟糕,因此应该进行调查以决定我们是否采取措施来改进它.

Here you can find rough demo app, that uses proposed approach. At the moment performance is frustratingly bad, so it should be investigated to decide if we to do something to improve it.

这篇关于Android:使用比双线性更好的重采样算法调整位图大小(如 Lanczos3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆