2012-02-29 32 views
1

public final BufferedImage filter(BufferedImage src, BufferedImage dst)如何在Android上执行与AffineTransformOp.filter类似的操作?

在目的地BufferedImage转换源BufferedImage并存储该结果 。
如果两个图像的颜色模型不匹配,则会执行转换到目标颜色模型的颜色 。 如果目的图像是null,则创建一个BufferedImage,其源 ColorModel。 由 getBounds2D(BufferedImage)返回的矩形的坐标不一定与此方法返回的 BufferedImage的坐标相同。如果矩形的左上角坐标 为负数,则不绘制矩形的这部分。如果矩形的左上角坐标为正,那么在目的地BufferedImage中的该位置处绘制的经过滤的图像是

我有下面的代码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); 

在Android中,我使用的,而不是为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 

我的问题是最后两个评论线。我可以在Android上做类似的事吗?谢谢。

回答

0

你可以做这样的事情

Matrix m = new Matrix(); 
matrix.postScale(scaleAmount, scaleAmount); 
Bitmap b = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), m, true); 

:BTW,甲骨文的JavaSE AffineTransformOp#filter有一个错误,当输出BufferedImage为null,它会创建一个BufferedImage但默认色彩空间,而不是一个的输入BufferedImage。)

相关问题