I've been working on a program that involves the rotation of a partially transparent image over a transparent form. The drawing of the image originally worked fine, I also set my custom panel's background color to a transparent light blue this worked fine as well. My problems started when I tried rotating my image.
In order to rotate it I had to convert the panel.getGraphics() over to a Graphics2D. When I did this the transparency went away, So I finished up on my rotation code and then read up on transparency. I found that I could set the composite of the Graphics2D and that is exactly what I did as seen here:
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
g2d.setColor(new Color(0, 0, 200, 90));
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
g2d.rotate(radians);
g2d.drawImage(img, 0, 0, null);
repaint();
}
When I run this I get the form as follows (Please note that this is not my normal image):
This is almost what I want except for it doesn't show the transparent blue background. However if I rotate the image the blue shows: