gpt4 book ai didi

java - 如何将 Canvas 复制到位图中

转载 作者:行者123 更新时间:2023-11-29 07:15:39 25 4
gpt4 key购买 nike

有什么方法可以将我刚刚绘制的 Canvas 内容复制到位图中吗?

编辑:澄清一下,我当前的绘图过程如下:

Canvas canvas = holder.lockCanvas();

if (canvas != null)
{
onDraw(canvas); // this does all the drawing

// at this point I would like to copy the canvas into a bitmap

holder.unlockCanvasAndPost(canvas); // this makes the canvas visible to the user
}

编辑:查看发布的第一个答案,我编写了以下代码:

if (grab_screen == -1) // draw and show on screen as normal
{
Canvas canvas = holder.lockCanvas();
if(canvas != null)
{
onDraw(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
else // draw into screengrab_bitmap[grab_screen]
{
Canvas canvas = new Canvas(screengrab_bitmap[grab_screen]);
onDraw(canvas);
grab_screen = -1;
}

这应该意味着如果我将 grab_screen 设置为 n,那么在下一次调用 onDraw 时,图像将被写入 screengrab_bitmap[n]。

最佳答案

创建一个“空”位图,将其分配给 Canvas (new Canvas(newBitmap) ),在该 Canvas 中绘制内容。您在 Canvas 上绘制的所有内容都将绘制在位图中。

关于java - 如何将 Canvas 复制到位图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9791089/

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