简体   繁体   English

在Java中将2D整数数组转换为位图

[英]Convert 2D array of integers to bitmap in Java

I have a 2D array of integers in Java. 我在Java中有一个2D整数数组。

I want to take this and output a bitmap image file where the red value of each pixel is the corresponding value in the array (blue and green values are 0). 我想以此为输出一个位图图像文件,其中每个像素的红色值是数组中的相应值(蓝色和绿色值为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 . 您可以创建一个BufferedImage并使用BufferedImage.setRGB(x,y,rgb) ,其中rgb是您的(byteArray[x][y] <<< 4) & 0xFF0000 Then save it using ImageIO.write(image, "bmp", file) . 然后使用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. 这不应该是一个简单的答案-但BMP图像的文件格式(最简单的)已明确定义。

Here's the BMP wiki . 这是BMP Wiki

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM