I'm having trouble with some custom Component I'm using in my project. It's drawing fine, but now I want to find coordinates of first pixel in certain color and have some troubles with it.
Here is my component code:
class DrawPad extends JComponent {
private LinkedList<Line> lines = new LinkedList<>();
DrawPad() {
setDoubleBuffered(true);
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
lines.add(new Line());
lines.getLast().add(e.getPoint());
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
lines.getLast().add(e.getPoint());
repaint();
}
});
}
void clear() {
lines.clear();
repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
if (!lines.isEmpty()) {
for (Line line : lines) {
// TODO
LinkedList<Point> points = line.getPoints();
Point previous = points.getFirst(), current = previous;
for (int i = 1; i < points.size(); i++) {
current = points.get(i);
g.drawLine(previous.x, previous.y, current.x, current.y);
previous = current;
}
}
}
}
}
I know it probably can be optimized, but it's not so important right now.
Can anyone help me to write a method that's searching for first pixel in certain color?
I recently find out that it has to do something with BufferedImage
, but don't know how to implement it. Any help would be appreciated.