Android自定义画笔图案/图片 [英] Android custom brush pattern/image

查看:288
本文介绍了Android自定义画笔图案/图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张8x8的图片。 (位图 - 可以更改)



我想做的是能够绘制一个形状,给定一个 Path 绘制对象到我的 SurfaceView



我所能做的一切就是用纯色填充形状。如何用模式绘制它。





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



我将如何去绘制这种花纹背景。


$ b $我也最终想要给它应用颜色。



到目前为止,我的理论是创建形状的剪辑区域,并平铺位图直到区域被覆盖,但这是处理中的极端过度。不是很理想。



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



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

解决方案

你检查过这个 blog 。它使用 BitmapShader



示例:

  //通过从资源文件夹加载图像来初始化位图对象
fillBMP = BitmapFactory .decodeResource(m_context.getResources(),R.drawable.cross);
//使用Bitmap对象初始化BitmapShader并设置纹理图块模式
fillBMPshader = new BitmapShader(fillBMP,Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);

fillPaint.setStyle(Paint.Style.FILL);
//将'fillBMPshader'分配给这个paint
fillPaint.setShader(fillBMPshader);

//使用paint对象绘制所需的任何形状的填充。
canvas.drawCircle(posX,posY,100,fillPaint);


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)

解决方案

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

这篇关于Android自定义画笔图案/图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆