Transparency issues with volatile images [solved]

java version: 1.6.0_11-b03
OS: windowsXP w/newest service pack
gfx card: nvidia 8400, nvidia 5900

startup:
0) create frame, set undecorated, turn off paint, set fullscreen mode

  1. create a buffer strategy with 2 buffers
  2. ImageIO.read() to load a 32-bit translucent png
  3. createCompatibleVolatileImage()
  4. validate()
  5. createGraphics()
  6. setComposite(AlphaComposite.Src)
  7. drawImage() into my VI from my BI
  8. dispose()

loop:

  1. getDrawGraphics()
  2. setColor() then fillRect() to black
  3. getLocalGraphicsEnvironment() & getDefaultScreenDevice().getDefaultConfiguration()
  4. validate()
  5. drawImage()
  6. show()
  7. dispose()

That works. My png is loaded and the transparent parts are indeed transparent. When I rotate the image however I end up with white areas in the corners. The transparent areas from the original image still work correctly, but in places where there is no original image information i’m getting white when I really want transparency.

rotation:

  1. getLocalGraphicsEnvironment() & getDefaultScreenDevice().getDefaultConfiguration()
  2. createCompatibleVolatileImage()
  3. validate()
  4. createGraphics()
  5. setComposite(AlphaComposite.Src)
  6. setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR)
  7. getTransform()
  8. new AffineTransform()
  9. rotate()
  10. transform()
  11. drawImage()
  12. setTransform()
  13. dispose()

When I rotate i’m creating a new VI, rotating the original VI, and copying the transformed image into my new VI (the original VI is preserved). I then draw the new image on my backbuffer and call show(). Rendering this new image gives me the white corners but the original transparency is still intact.

I was originally doing all of this with buffered Images and it worked correctly, but i’m at a point where i’m doing lots of image rotation which kills performance. Thus the switch to VIs.

I’m at at a loss. I’m not sure if i’m setting the incorrect composite on my surface, if my transparency is never being applied (or removed), or if i’m not correctly understanding how the image rotation works.

Additionally, if I create my VI during startup and do everything the same but skip the part where i copy my BI into my VI i get a white rectangle on my black backbuffer. I would think I would not see the white rectangle since i’m setting the composite, but I think i’m missing something.

regards,
~don

Shortly after making this point a friend found the problem. The example I found on the internet suggested setting the transparency this way:

g2d.setComposite(AlphaComposite.Src);
g2d.[b]setColor/b;
g2d.clearRect(0, 0, width, height);

It appears you need to use either setColor() with fillRect() OR setBackground() with clearRect() AND you must use New Color(0,0,0,0) instead of Color.black
So something like:

g2d.setComposite(AlphaComposite.Src);
g2d.setBackground(new Color(0,0,0,0));
g2d.clearRect(0, 0, width, height);

or

g2d.setComposite(AlphaComposite.Src);
g2d.setColor(new Color(0,0,0,0));
g2d.fillRect(0, 0, width, height);

~don