Android自定义画笔图案/图像

时间:2012-11-09 11:29:05

标签: android design-patterns drawing paint brush

我有8x8图像。 (位图 - 可以更改)

我想要做的是能够在我的Path上给出一个PaintSurfaceView对象来绘制形状。

目前,我所能做的就是用纯色填充形状。如何用图案绘制它。

Example

在图像中,您可以看到画笔图案(十字)。它可以是从十字架到甜甜圈或精灵的任何东西。

我将如何绘制此图案背景。

我最终也想要应用颜色。

到目前为止,我的理论是创建一个形状的剪辑区域,并平铺位图直到覆盖区域,但这在处理过程中极度过度。听起来也不理想。

在着色方面,我可以将画笔编辑为alpha,用背景颜色填充,然后在顶部绘制图像。真正的问题是这种模式的平铺。

我发现了一些类似性质的问题,都没有答案,和/或不适用于我的情况。 (在视图等上使用xmls)

1 个答案:

答案 0 :(得分:18)

你选中了这个blog吗?它使用BitmapShader

示例:

    //Initialize the bitmap object by loading an image from the resources folder  
    fillBMP = BitmapFactory.decodeResource(m_context.getResources(), R.drawable.cross);  
    //Initialize the BitmapShader with the Bitmap object and set the texture tile mode  
    fillBMPshader = new BitmapShader(fillBMP, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);  

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

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