Android custom brush pattern/image

早过忘川 提交于 2019-12-21 02:25:10

问题


I have an 8x8 Image. (bitmap - can be changed)

What I want to do is be able to draw a shape, given a Path and Paint object onto my SurfaceView.

At the moment all I can do is fill the shape with solid colour. How can I draw it with a pattern.

In the image you can see the brush pattern (The cross). It can be anything from a cross to a donut or an elf.

How would I go about drawing this pattern background.

I also eventually want to apply colours to it.

So far, my theory is to create a clip area of the shape, and tile the bitmaps until area is covered, but this is extreme overkill in processing. Nor sound ideal.

In terms of colouring, I can edit the brushes to be alpha, fill the same with background colour, then draw the images on top. The real issue it the tiling of such patterns.

Ive found a few questions of a similar nature, all unanswered, and/or not applicable to my situation. (use of xmls on views etc)


回答1:


Did you checked this blog. Its using BitmapShader

Example:

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


来源:https://stackoverflow.com/questions/13307282/android-custom-brush-pattern-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!