0

我需要将 Java 代码更改为 Android。

我有 Java 代码BufferedImageGraphics. 我应该如何将以下 Java 代码更改为 Android。

我的代码是,

public static BufferedImage buff(BufferedImage bi){
    if (isGray(bi)){
        return bi;
    }
    BufferedImage gray = new BufferedImage(bi.getWidth(), bi.getHeight(), 10);
    Graphics gr = gray.getGraphics();
    gr.drawImage(bi, 0, 0, null);
    gr.dispose();
    return gray;
}

提前致谢。

4

1 回答 1

0

javax.imageio isn't in the Android SDK, but the Bitmap class can be used, if you want convert to gray, you can use this:

public static Bitmap toGrayscale(Bitmap bm) {
    Bitmap bmpGrayscale = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.RGB_565);

    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);

    c.drawBitmap(bm, 0, 0, paint);
    return bmpGrayscale;
}
于 2013-09-25T07:12:40.360 回答