简体   繁体   中英

Convert Array of RGB Integers to Bitmap

We know that, we can get rgb of bitmap image with using the code as follow :

BufferedImage img = ImageIO.read(new File(bitmapURL));
int[] pixels = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth());

And, after executing this parts of code, we have an array of integers that contains 4 bytes for Alpha, Red, Green and Blue colors of any pixel. So, i want to know that how can we convert an array of integers like int [] myPixels; to Bitmap ? Could any one please help me to reach this?

Thanks in advance :)

You can directly use this :

image.setRGB(0, 0, width, height, pixels, 0, width);

Source


BufferedImage im = new BufferedImage(width, height);

for (int i = 0; i < width; i++) {
  for (int j = 0; j < height; j++) {
    im.setRGB(...);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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