Olá, tenho um código que pinta uma imagem que esta em preto e branco e fica colorida que vi em um post, uso ela assim que eu inicio a tela principal do sistema.
o problema é q ela pega a tela toda e na frente de todos os outros componentes…
como adiciono essa imagem e o efeito dentro do Jframe?
segue o códgio:
private BufferedImage carregarImagem(String image)
{
try {
//Carrega a imagem do disco
BufferedImage img = ImageIO.read(new File(image));
BufferedImage imagem = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration()
.createCompatibleImage(getWidth(), getHeight(), Transparency.TRANSLUCENT);
Graphics2D g2d = imagem.createGraphics();
g2d.drawImage(img, 0,0, imagem.getWidth(), imagem.getHeight(), 0,0, img.getWidth(), img.getHeight() , this);
g2d.dispose();
//Retornamos a imagem redimensionada e otimizada
return imagem;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public class DemoThread implements Runnable {
@Override
public void run() {
try {
while (cont != 100) {
repaint();
Thread.sleep(30); //15 fps
cont = cont + 1;
}
} catch (InterruptedException e) {
}
}
}
@Override
public void paint (Graphics g) {
BufferedImage buffer = new BufferedImage(img1.getWidth(), img1.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = buffer.createGraphics();
g2d.drawImage(img1,0,0, this);
g2d.setComposite(AlphaComposite.SrcOver.derive(alpha));
g2d.drawImage(img2, 0,0, this);
//Variamos o alpha
alpha += add;
if (alpha > 0.98) {
add = -0.02f;
}
g2d.dispose();
g.drawImage(buffer, 0,100,this);
}