Creating a BufferedImage Using Pixels int []

I use a sprite sheet and set it up to get the int [] pixel of each sprite, I'm just not sure how to use this int [] pixel to create a separate image.

my code is:

i=0;
BufferedImage[] bi = new BufferedImage[];
for(y) {
   for (x) {
      int[] pixels = null;
      Vars.TILE_SHEET_BI().getRaster().getPixels(x, y, 16, 16, pixels);
      bi[i] = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
  bi[i].getRaster().setPixels(0, 0, 16, 16, pixels);
  i++;
   }
}
+4
source share
1 answer

Why not just call getSubImage(...)BufferedImage? I know that this is what I would do, and actually what I did.

For example, see the code for my answer to this question .

What takes this sprite sheet:

flag sprite sheet

and creates this graphical interface with it:

enter image description here

+5
source

All Articles