问题描述
我有一个8x8的形象。 (位图 - 可以改变)
I have an 8x8 Image. (bitmap - can be changed)
我想要做的是能够绘制形状,给定一个路径
和油漆
对象到我 SurfaceView
。
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.
香港专业教育学院发现了一个类似性质的几个问题,都无人接听,和/或不适用我的情况。 (上意见等使用XMLS的)
Ive found a few questions of a similar nature, all unanswered, and/or not applicable to my situation. (use of xmls on views etc)
推荐答案
你有没有检查过这的。它使用 BitmapShader
Did you checked this blog. Its using 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);
这篇关于Android的自定义画笔模式/图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!