开发者

Convert 2D array of integers to bitmap in Java

开发者 https://www.devze.com 2023-01-20 13:43 出处:网络
I have a 2D array of integers in Java. I want to take this and output a bitmap image file where the red value of each pixel is the corresponding value in the ar开发者_如何学Pythonray (blue and green

I have a 2D array of integers in Java.

I want to take this and output a bitmap image file where the red value of each pixel is the corresponding value in the ar开发者_如何学Pythonray (blue and green values are 0).

Does anyone know how to do this? Thanks.


You can create a BufferedImage and use BufferedImage.setRGB(x, y, rgb), where rgb is your (byteArray[x][y] <<< 4) & 0xFF0000. Then save it using ImageIO.write(image, "bmp", file).


There nothing to do but to do it, unfortunately. That's not supposed to be a flip answer - but the file format for a BMP image, which is the easiest, is well defined.

Here's the BMP wiki.

0

精彩评论

暂无评论...
验证码 换一张
取 消