Olá , será que alguém sabe como eu faço para atualizar uma imagem, no momento da execução. Esse programa abaixo, pinta uma imagem branca na cor vermelha, porém só consigo ver depois que o programa termina. Estou usando o seguinte código:
import java.awt.;
import java.awt.event.;
import java.awt.image.BufferedImage;
import java.io.;
import java.io.File;
import javax.swing.;
import javax.imageio.ImageIO;
public class Pixel extends JApplet {
public static void main(String s[]) throws IOException {
JFrame f = new JFrame("Pixel");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JApplet applet = new ImageOps();
f.getContentPane().add("Center", applet);
// applet.init();
BufferedImage imagem = ImageIO.read(new File("test15.jpg"));
int w = imagem.getWidth();
int h = imagem.getHeight();
int[] pixels = imagem.getRGB(0, 0, w, h, null, 0, w);
Pixel r = new Pixel();
for (int col = 0; col <320; col++) {
for (int lin = 0; lin <239; lin++) {
if(pixels[ w*lin + col] == new Color(255, 255, 255).getRGB()){
pixels[ w*lin + col] =
new Color(255, 0, 0).getRGB();
}
}
}
imagem.setRGB(0, 0, w, h, pixels, 0, w);
ImageIO.write(imagem, "JPG", new File("arteabstrata.jpg"));
// f.pack();
// f.setSize(new Dimension(550,550));
// f.setVisible(true);
}
private int nextInt(int i) {
return i;
}
/** Creates a new instance of Pixel */
public Pixel() {
}
}