Reputation:
I have one class named MyView that extends View..In my options menu i have four types of color.
What i want is when i select green and draw path on canvas it should draw green path and when i select red it should draw red path and previous green should be as it is ...
I got success in drawing multiple paths of various colors but at one time only one color is holding in canvas .. so what can i do to draw multiple color of paths on canvas ??
Upvotes: 3
Views: 2298
Reputation: 83729
The way i've done this is to store the color along with the path by subclassing Path:
private class DrawingPath extends Path
{
public DrawingPath(float w, int c)
{
Width = w;
Color = c;
}
public float Width;
public int Color;
}
Then when i draw each of the paths I have I set the color beforehand.
As you can see you can also set the width with this code so you can change the stroke width for each path.
To draw this i used:
mCanvas.drawColor(Color.WHITE);
for (DrawingPath p : mPaths)
{
mPaint.setColor(p.Color);
mPaint.setStrokeWidth(p.Width);
mCanvas.drawPath(p, mPaint);
}
invalidate();
Upvotes: 1