I draw graphics in frame with this methods.
public void paint(Graphics g) {
screenImage = createImage(1280, 720);
screenGraphic = screenImage.getGraphics();
screenDraw((Graphics2D) screenGraphic);
//g.drawImage(BG, 0, 0, null);
g.drawImage(screenImage, 0, 0, null);
}
public void screenDraw(Graphics2D g) {
g.drawImage(BG, 0, 0, null);
Graphics2D g2 = (Graphics2D)g;
if(isMainScreen) {
//g2.setComposite(alphaComposite);
g2.drawImage(selectedImage, 100, 220, null);
}
paintComponents(g);
this.repaint();
}
I want to have selectedImage to be transparency 50% or other integer.
private Image selectedImage = new ImageIcon(Main.class.getResource("../pic/something.jpg")).getImage();
this is selectedImage, and it works well.
Adapt a bit of Image -> BufferedImage code, and then you can set each pixel to be transparent
If you use
ImageIO.read(File)
instead ofImageIcon.getImage()
, it will give you aBufferedImage
directly