如何使用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;
}