2016-08-01 116 views
-1

如何使用BLACK和WHITE像素阵列创建黑白图像?从黑色和白色1D阵列像素创建图像

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; 
    } 

回答

相关问题