2012-02-29 73 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。)

相關問題