public final BufferedImage filter(BufferedImage src, BufferedImage dst)
Transforms the source
BufferedImageand stores the results
in the destinationBufferedImage.
If the color models for the two images do not match, a color
conversion into the destination color model is performed.
If the destination image isnull, aBufferedImageis created with the source
ColorModel.
The coordinates of the rectangle returned by
getBounds2D(BufferedImage)are not necessarily the same as the coordinates of the
BufferedImagereturned by this method. If the upper-left corner coordinates
of the rectangle are negative then this part of the rectangle is not drawn. If the
upper-left corner coordinates of the rectangle are positive then the filtered image is
drawn at that position in the destinationBufferedImage.
I had the following code on Java 1.6:
//Make image always std_height tall
double scaleAmount = (double) std_height / (double) characterImage.getHeight();
AffineTransform tx = new AffineTransform();
tx.scale(scaleAmount, scaleAmount);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
characterImage = op.filter(characterImage, null);
In Android, i’m using Matrix instead of AffineTransform:
//Make image always std_width wide
float scaleAmount = (float) std_width / (float) characterImage.getWidth();
//AffineTransform tx = new AffineTransform();
//tx.scale(scaleAmount, scaleAmount);
Matrix mx = new Matrix();
mx.setScale(scaleAmount, scaleAmount);
//AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); //Can't use this on Android
//characterImage = op.filter(characterImage, null); //Can't use this on Android
My problem is with the last two commented lines. Can i do something like it on Android? Thanks.
You can do something like
(Note: BTW, Oracle JavaSE
AffineTransformOp#filterhas a bug when the outputBufferedImageis null, it creates aBufferedImagebut with default colorspace, not the one of the input BufferedImage.)