Working with Paint

Before we can do any drawing, we need to construct a Paint object. The Paint object will allow us to define the color, size of the stroke, and style of the stroke used when drawing. We can therefore think of the Paint as both paint and brush.

Paint paint = new Paint(); paint.setColor(Color.GREEN); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(10);

The foregoing snippet of code creates a Paint object, sets its color to be green, defines that we want to draw the outline of shapes rather than fill them in, and sets the width of that stroke to be 10 pixels.

Let's examine each of these methods individually.

Was this article helpful?

0 0

Post a comment