Question

In Android I'm using Canvas.drawPath( Path, Paint ) to fill a Path. I've set the Paint variable to use a BitmapShader & the Style to Fill. This method works fine until I try to use additional clipping, i.e. I try to draw to a sub-region within the Path like so

theCanvas.clipRect( visibleRect, Region.Op.REPLACE );
theCanvas.clipRect( additionalClipping, Region.Op.INTERSECT );
theCanvas.drawPath( path, paint );

My desired result is to have the texture within the BitmapShader within the Paint, drawn to a rectangular area intersected with edge of my path.

But the actual result of this is to have the texture tiled all over the Path area - the clipping I set on the Canvas seems to have had no effect.

Its almost as if calling Canvas.drawPath internally calls Canvas.setClip( Path, Region.Op.Replace ).

Any help is much appreciated, thank you.

Was it helpful?

Solution

Short answer to my own question is yes, Canvas.drawPath does use the clipping set on the canvas as well as the shape of the path itself, it does not overwrite it.

theCanvas.clipRect(new Rect(632, 269, 1265, 539 ), Region.Op.REPLACE);
theCanvas.drawPath( theNativePath, thePaint );

The above code produces my path, painted with my texture, but within the combined area of the path and the rectangle I applied to the clipping in the canvas beforehand. My texture still looks wrong, but the issue is not with the clipping, it behaves as intended.

Upon further investigation this morning I've narrowed the problem down to something I've done wrong with either the BitmapShader in the Paint object, or its an issue in my texture cache which supplies the BitmapShader.

Apologies for any confusion - I will now put on the 'dunce' hat.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top