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).
There are many good libraries for Java as discussed for example here: Java - resize image without losing quality
However it's always depended on Java awt classes like java.awt.image.BufferedImage
, so it can't be used in Android.
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)?
Unfortunately Android uses android.graphics.Bitmap which does not exist in java while java uses java.awt.image.BufferedImage that does not exist in android :-(
I donot have a ready to use library for android
but a path how to port a java-awt specific lib to a platform independat java lib with platfrom specific handlers for android and awt/j2se
In the java rescale lib you have to hide all java-awt specific classes (like BufferedImage) behind an interface IBitmap
and implement that interface for j2se and independantly for Android.
I have done this successfully for exif/icc/ipc metadata processing and implemented interface pixymeta-lib/.../IBitmap.java with implementation for j2se pixymeta-j2se-lib/.../j2se/BitmapNative.java and android pixymeta-android-lib/.../android/BitmapNative.java
So I have these packages
IBitmap
interfaceIBitmap
IBitmap
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.
EDIT
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With