gpt4 book ai didi

Android自定义画笔图案/图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:56 26 4
gpt4 key购买 nike

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

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

目前我所能做的就是用纯色填充形状。我怎样才能用图案画出来。

Example

在图像中,您可以看到画笔图案(十字)。它可以是任何东西,从十字架到 donut 或小 Sprite 。

我将如何绘制这个图案背景。

我最终也想给它上色。

到目前为止,我的理论是创建形状的裁剪区域,然后平铺位图直到区域被覆盖,但这在处理过程中是极端的矫枉过正。听起来也不理想。

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

我发现了几个性质相似的问题,但都没有答案,和/或不适用于我的情况。 (在 View 等上使用 xml)

最佳答案

你检查过这个吗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);

关于Android自定义画笔图案/图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13307282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com