How to apply dot brush color in paint android application?

I use the following code to apply font color when a user clicks on a color in the form of a path, such as RED.

mPaint.setColor(getResources().getColor(R.color.color2));

And the color2 file in color.xml

<color name="color2">#FF3C00</color>

Now I am facing a problem when applying the following color.

RED COLOR WITH WHITE DOTS

I use canvas to draw paint by touching it in my application, and want to draw something like an attached screen on canvas. I can draw it, but it looks like a solid color (I mean a full circle, but not a dot inside)

Please help me find this.

+5
source share
1 answer

You can use BitmapShader to achieve this.

Here is a sample code .. Try this code, I hope it works.

Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.shader);  
//Initialize the BitmapShader with the Bitmap object and set the texture tile mode  
BitmapShader mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);  

fillPaint.setStyle(Paint.Style.FILL);  
//Assign the 'fillBMPshader' to this paint  
fillPaint.setShader(mBitmapShader);  

//Draw the fill of any shape you want, using the paint object.
canvas.drawCircle(posX, posY, 100, fillPaint);
+3

All Articles