如何在Paint android应用程序中应用带点的笔刷颜色?

时间:2013-04-26 04:50:48

标签: android paint

当用户点击像RED这样的特定颜色时,我使用以下代码来应用字体颜色。

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

color.xml文件中的color2是

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

现在我在应用以下颜色时遇到问题。

RED COLOR WITH WHITE DOTS

我在我的应用程序中使用画布来触摸它时画画,我想在画布上绘制类似附加画面的东西。我能够绘制但它看起来像纯色(我的意思是完整的圆圈而不是内部的点点)

请帮我找到这个。

1 个答案:

答案 0 :(得分:3)

您可以使用BitmapShader来实现这一目标..

以下是示例代码..尝试此代码,我希望它能正常工作..

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);