0

I'm currently working on simple drawing application on Android, which is supposed to work like Microsoft's Paint. To do so, I'm using drawOwal method from Canvas class, as long as I move mouse/finger slowly everything looks fine, but when I make it fastert, instead of smooth line, it is splitted to small circles.

enter image description here

How can I improve my code using RectF/drawOval so there won't be those gaps?

My drawing code looks like this:

@Override
protected void onDraw(Canvas canvas) {
    for(Shape draw: punkty) {
        paint.setColor(draw.getColor());
        if (draw.getShape() == 0)
            canvas.drawOval(draw.getFigure(), paint);
        else if (draw.getShape() == 1)
            canvas.drawRect(draw.getFigure(), paint);
    }
}
@Override
public boolean onTouchEvent(MotionEvent event) {
    shapeToDraw.setFigure(new RectF(event.getX() - shapeToDraw.getSize(), event.getY() - shapeToDraw.getSize(), event.getX() + shapeToDraw.getSize(), event.getY() + shapeToDraw.getSize()));
    punkty.add(new Shape(shapeToDraw.getColor(), shapeToDraw.getFigure(), shapeToDraw.getSize(), shapeToDraw.getShape()));
    invalidate();
    return true;
}
BednarQ
  • 139
  • 3
  • 15
  • see http://stackoverflow.com/q/8287949/794088 – petey Feb 15 '17 at 21:15
  • Also, constantly creating a new Shape on each touch event isn't going to help. Object instantiation can be expensive, reuse is preferable. Try to avoid new in touch event and draw handlers, and if you must new try to do it only on downs and ups, rather than moves. – Gabe Sechan Feb 15 '17 at 21:20

0 Answers0