如何在android中的Bitmap上绘图?

发布于 2024-10-02 04:45:59 字数 305 浏览 2 评论 0原文

我试图弄清楚如何在 android 中的位图上绘制,并保留这些更改的位图的副本以用于撤消功能。

Bitmap b = ...
Paint p = new Paint();
canvas.drawBitmap(b, new Matrix(), null);
canvas.drawCircle(0,0,20,20);
//does Bitmap b have the circle drawn on it next time?

或者如何在画布上绘制位图后获取位图(我想保留一堆位图以及画布绘制所应用的更改)?也许我的想法完全错误。

I'm trying to figure out how to draw on a bitmap in android, and keep a copy of these changed bitmaps for an undo function.

Bitmap b = ...
Paint p = new Paint();
canvas.drawBitmap(b, new Matrix(), null);
canvas.drawCircle(0,0,20,20);
//does Bitmap b have the circle drawn on it next time?

Or how do I get the bitmap after its been drawn on with the canvas(I want to preserve a stack of bitmaps with the changes applied by canvas drawing)? Maybe I'm going about this entirely wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-10-09 04:45:59

使用 new Canvas(Bitmap 位图) 提供带有 BitmapCanvas,其中将包含绘图操作的结果。

您使用 drawBitmapCanvas 上绘制的原始 Bitmap 永远不会被修改。

用户完成每个操作后,您可以:

  • 在内存中保留已完成操作的列表,
  • 使用 Bitmap.compress 将中间结果保存到外部存储

另一种方法是使用 LayerDrawable 将连续的绘制操作堆叠在一起。您可以想象允许用户禁用已完成的每个单独操作。

Use new Canvas(Bitmap bitmap) to provide a Canvas with a Bitmap which will contain the result of your drawing operations.

The original Bitmap that you draw on your Canvas with drawBitmap will never be modified.

After each operation done by the user you might:

  • keep in memory a list of the operations done
  • save intermediate results to external storage with Bitmap.compress

Another approach could be to use a LayerDrawable to stack successive drawing operations on top of each other. You can imagine allowing the user to disable each individual operation done.

再浓的妆也掩不了殇 2024-10-09 04:45:59

您可以在此处查看如何绘制文本的完整指南:

https:// www.skoumal.net/en/android-how-draw-text-bitmap/

长话短说:

复制位图以使其可变,并基于它创建 Canvas。

You can see complete guide how to draw text here:

https://www.skoumal.net/en/android-how-draw-text-bitmap/

Long story short:

Copy your bitmap to make it mutable and create Canvas based on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文