8bitslime
8bitslime

Reputation: 164

Creating a BufferedImage using pixels int[]

I'm using a sprite sheet and have it set up to get the pixel int[] of each sprite, I'm just not sure how to use that pixel int[] to make a seperate image.

my code:

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

Upvotes: 4

Views: 225

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

Why not simply call getSubImage(...) on the BufferedImage? I know that that is what I'd do, and in fact what I've done.

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

Which takes this Sprite Sheet:

flag sprite sheet

and creates this GUI with it:

enter image description here

Upvotes: 5

Related Questions