I'm very beginner at java, until this day i tried to do what i thought myself. So the day is here;
i've got all pixels of an image to array as rgb. i want to click a button and to make animated-like image has created pixel by pixel.
this is what i did that not works;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
public class pixell extends JFrame {
int x = 0;
int y = 0;
JButton btn;
JButton btn2;
JButton btn3;
JLabel lbl1;
File file = new File("C:\\Users\\Gok\\Desktop\\df.jpg");
BufferedImage image = ImageIO.read(file);
int w = image.getWidth();
int h = image.getHeight();
int[][] rp = new int[w][(h)];
BufferedImage rsm = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
JLabel background;
ImageIcon img = new ImageIcon(rsm);
JPanel jp;
public pixell() throws IOException {
// TODO Auto-generated constructor stub
this.setSize(612, 612);
this.setLayout(null);
btn = new JButton("al");
btn2 = new JButton("yaz");
btn.setBounds(100, 100, 100, 100);
btn2.setBounds(100, 200, 100, 100);
background = new JLabel(img);
background.setBounds(10, 10, w, h);
this.add(btn);
this.add(btn2);
this.add(background);
btn.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
// Getting pixel color by position x and y
int clr = image.getRGB(i, j);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
rp[i][j] = clr;
}
}
}
});
btn2.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
rsm.setRGB(i, j, rp[i][j]);
jp.setVisible(false);
jp.revalidate();
jp.repaint();
jp.setVisible(true);
jp.revalidate();
jp.repaint();
}
}
}
});
}
}