2 Replies Latest reply: Jul 28, 2011 1:07 PM by 878433 RSS

    Cant't draw picture with alpha on tranlucent window

    878433
      I cant draw picture with alpha on my translucent window, it only looks fine when everything behind window is completely black.
      I have been trying with png, jpg, and gif, and only gif works fine.
      Here's picture that I used:
      http://i52.tinypic.com/i3b40n.png
      Code:
       
      import java.awt.Frame;
      import java.awt.Graphics;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.image.BufferedImage;
      import java.io.File;
      
      import javax.imageio.ImageIO;
      
      import com.sun.awt.AWTUtilities;
      import com.sun.jna.platform.WindowUtils;
      
      
      public class TranslucentWindowPicture {
           
           public static void main(String[] args) {
                
                Frame frame = new Frame(WindowUtils.getAlphaCompatibleGraphicsConfiguration());
                frame.setSize(300,300);
                AWTUtilities.setWindowOpaque(frame, false);
                frame.setVisible(true);
                frame.addWindowListener(new WindowAdapter() {
                     public void windowClosing(WindowEvent e) {
                          System.exit(0);
                     }
                });
                
                BufferedImage image;
                
                try {
                     image = ImageIO.read(new File("path/to/file"));
                } catch (Exception e) {
                     System.err.println(e);
                     image = null;
                }
                
                Graphics g = frame.getGraphics();
                g.drawImage(image, 0, 0, frame);
           }
      }
       
      Thank you in advance.