如何在安卓的绘画应用中使用点状刷子来上色?

5
我正在使用以下代码来在用户单击特定颜色(如红色)时应用字体颜色。
mPaint.setColor(getResources().getColor(R.color.color2));
< p >而color.xml文件中的color2颜色为

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

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

红底白点

我正在使用canvas来绘制触摸应用程序中的图画, 我想在canvas上绘制类似于附加屏幕的内容。我已经能够绘制它,但看起来像是一个实心的圆圈而不是点点在里面。

请帮助我找到这个。

1个回答

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

当我使用这段代码时,它只绘制一次,并且不会在之前绘制的画上继续绘制。 - Muhammad Umair Shafique

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接