Using BufferedImage for GuiNode

This topic appears in a few places, but not the specifics (as far as I can find):

I want to use a BufferedImage GuiNode and I can do this using the Picture class if the Buffered image is creatd by loading a PNG. For example:

     BufferedImage background = ImageIO.read(resourceClass.getResourceAsStream("icons" + File.separatorChar + "background.png"));
     texture.setImage(new AWTLoader().load(background , true));

However, it does not seem to work for buffered images generated like this:

  background = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
  int color = 125;
  for (int y = 0; y < background .getHeight(); y++)
  {
     for (int x = 0; x < background .getWidth(); x++)
     {
        background .setRGB(x, y, color);
     }
  }
     texture.setImage(new AWTLoader().load(background , true));

Am I missing something?

Thanks in advance,
MJ

If color is 125 for a ABGR image then it is all red with alpha zero. Your image would be completely transparent.

Edit: never mind… didn’t notice the setRGB. I do this all the time, though so there must be something with your setup.

Actually, my guess is that alpha is still 0. Try getting the raster data and poking the raw ABGR values in directly.

int[] pixels = ((DataBufferInt)background.getRaster().getDataBuffer()).getData();

Then set all of the pixels to 0xffffffff to test.

That was it. I switch to BufferedImage.TYPE_INT_RGB and it works fine. I then swtiched back to TYPE_INT_ARGB and set the alpha value properly and it works fine.

Thanks!