从黑白1D阵列像素创建图像

时间:2016-08-01 10:25:33

标签: java image rgb

如何使用BLACK和WHITE像素数组创建黑白图像?

int pixels[]= {-1, -16777216,-16777216,-16777216....}
Color w = new Color(Color.WHITE.getRGB());
int wi = w.getRGB();

Color b = new Color(Color.BLACK.getRGB());
int bi = b.getRGB();

我试图使用此代码,但结果只有几个黑色像素。

  public static BufferedImage getImageFromArray(int[] pixels, int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        WritableRaster raster = (WritableRaster) image.getData();
        raster.setDataElements(0, 0, width, height, pixels);
        return image;
    }

1 个答案:

答案 0 :(得分:0)

不确定你想要创造什么,但这里有一些很好的例子: http://www.lac.inpe.br/JIPCookbook/1100-create-bw.jsp