import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Point;
import java.io.File;
import java.util.ArrayList;
class getting_leftsidepixel1 {
static int temp1,temp2;
static int count=0;
static int x1;
static BufferedImage image;
private static void repaintAndDelay(BufferedImage image) {
_imageLabel.setIcon(new ImageIcon(image));
_imageLabel.repaint();
try {
Thread.sleep(1);
} catch (Exception ignore) {
}
}
public static void floodFill(BufferedImage image, int x, int y,
int fillColor) {
java.util.ArrayList<point> examList = new java.util.ArrayList<point>();
int initialColor = image.getRGB(x, y);
examList.add(new Point(x, y));
System.out.println("array list is "+examList);
System.out.println("x value is"+x);
System.out.println("y value is "+y);
while (examList.size() > 0) {
Point p = examList.remove(0);
try
{
if (image.getRGB(p.x, p.y) == initialColor) {
x = p.x;
y = p.y;
image.setRGB(x, y, fillColor);
examList.add(new Point(x - 1, y));
examList.add(new Point(x + 1, y));
examList.add(new Point(x, y - 1));
examList.add(new Point(x, y + 1));
repaintAndDelay(image);
}
}catch(Exception e)
{
temp1=x;
temp2=y;
}
}
}
public static int packRgb(int r, int g, int b) {
return (r * 256 + g) * 256 + b;
}
static JLabel _imageLabel;
public static void main(String[] args) throws Exception {
image = ImageIO.read(new File("inputleft1.png"));
final int height = image.getHeight();
final int width = image.getWidth();
System.out.println("height"+height);
System.out.println("width"+width);
int countrow = 0;
int countcol = 0;
int newrow = width - height;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (countrow == newrow) {
Color c = new Color(image.getRGB(i, j));
int a = c.getRed();
int b = c.getGreen();
int c1 = c.getBlue();
if (a == 255 && b == 255 && c1 == 255) { + "j value" + j);
int yellow = packRgb(255, 0, 0);
System.out.println(temp1);
System.out.println(temp2);
if(temp1!=i&&temp2!=j)
{
floodFill(image, i, j, yellow);
}
}
}
countcol++;
}
countrow++;
}
JLabel imageLabel = new JLabel();
_imageLabel = imageLabel;
imageLabel.setIcon(new ImageIcon(image));
imageLabel.setText("Filling the circle with red color ...");
javax.swing.JFrame window = new javax.swing.JFrame();
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
window.add(imageLabel);
window.pack();
window.setVisible(true);
imageLabel.setIcon(new ImageIcon(image));
ImageIO.write(image, "png",new File("finalimage3.png"));
}
}</point></point>