1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BigP extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
public BigP()
{
super("BigP");
setBounds(0,0,600,450);
this.setResizable(false);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent ev)
{ dispose();
System.exit(0);
}
});
setContentPane(new panel());
setVisible(true);
}
public static class panel extends JPanel
{
/**
*
*/
private static final long serialVersionUID = 1L;
BufferedImage image = new loadzImage().loadImage("an.jpg");
public Image img ;
Vector <String> region = new Vector<String>();
Vector<String> lespixel = new Vector<String>();
String val= new String() ;
boolean [][] test=new boolean [image.getWidth()][image.getHeight()];
int [] pixel= new int[image.getWidth()* image.getHeight()];
String [][] rar= new String[image.getWidth()][image.getHeight()];
public panel()
{
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
test[i][j]=false;
}}
test[0][0]=true;
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); j++) {
test[i][j]=false;
}}
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
take_it(x,y,image.getRGB(x,y));
test[x][y]=true;
if (lespixel.isEmpty()==false)
{
region.add(" (region suivante) "+lespixel);
System.out.println( " les region : " +region);
}lespixel.removeAllElements();
}}
}
private void take_it(int x, int y, int rgb)
{
if (x < 0 || y < 0) return;
if (x >= image.getWidth(this)) return;
if (y >= image.getHeight(this)) return;
if (image.getRGB(x,y)/10000099 == rgb/10000099 && test[x][y]==false )
{ test[x][y]=true;
lespixel.add("("+x+","+y+")");
take_it(x-1,y,rgb);
take_it(x,y+1,rgb);
take_it(x+1,y,rgb);
take_it(x-1,y+1,rgb);
take_it(x+1,y+1,rgb);
take_it(x+1,y+1,rgb);
}
}
}public static void main (String[] args)
{
new BigP();
}} |
Partager