i have a png image of star and i want draw that shape using Line or Elippse by reading image or pixel then convert it to star shape using draw line or draw ellipse
, but there is a problems of
outliers and cluster ,
also why iam getting ouliers if there is no black color present in the first image.
my full code is
public class GetPixelColor extends JPanel
{
static int x;
static int y;
public static void main(String args[]) throws IOException{
GetPixelColor gh = new GetPixelColor();
JFrame frame = new JFrame("Points");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.add(points);
frame.setSize(1600, 1600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.add(gh);
File file= new File(“f://sss1.jpg”);
BufferedImage image = ImageIO.read(file);
// Getting pixel color by position x and y
int x1 = 0;
int y1 = 0;
int x2 = image.getWidth();
int y2 = image.getHeight();
for( x=0;x<x2;x++)
{
for( y=0;y<y2;y++)
{
int clr= image.getRGB(x,y);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
if(red>=0 && red<=1 && blue>=0 && blue<=1 && green>=0 && green<=1)
{
System.out.println("Red Color value = "+ red);
System.out.println("Green Color value = "+ green);
System.out.println("Blue Color value = "+ blue);
System.out.println("position x "+ x+“y==”+y);
gh.hello(x,y);
}
}
}
}
void hello(int x,int y)
{
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponents(g);
Paint paint = new GradientPaint(20, 0, Color.blue,
40, getHeight(), Color.yellow, true);
((Graphics2D) g).setPaint(paint);
Graphics2D g2d = (Graphics2D) g;
//g2d.setColor(Color.BLACK);
Shape fg = new Rectangle2D.Double(x,y,1,1);
g2d.fill(fg);
// g2d.drawLine(x, y,x, y);
}
}