开发者

canvas drawing Paint loop code

开发者 https://www.devze.com 2023-02-15 22:01 出处:网络
I\'m drawing circles to the canvas ever开发者_StackOverflow社区y time I touch the screen.I add them to an arraylist of paths in the onTouch method. In my onDraw method, I loop through the array, drawi

I'm drawing circles to the canvas ever开发者_StackOverflow社区y time I touch the screen. I add them to an arraylist of paths in the onTouch method. In my onDraw method, I loop through the array, drawing them.

When I try to change the paint of one of the circles, it changes them all. I don't want this, just want it to apply to one specific circle. How can I do that?

Code:

//on touch method
case MotionEvent.ACTION_DOWN:
    mode = Drag;
    x =(int) event.getX();
    y =(int) event.getY();
    path = new Path();
    path.addCircle(event.getX(), event.getY(), 8, Path.Direction.CCW);
    mpaint.setARGB(255, mcolor[0],100, mcolor[2]);
    circle.add(path);
    invalidate();

//on draw method
for (Path c : circle) {
    canvas.drawPath(c, mpaint);
}


Two options:

  1. Store a separate Paint object along with each circle
  2. Query the Paint for the current values of whatever you are changing, and then restore them after drawing the circle.
0

精彩评论

暂无评论...
验证码 换一张
取 消