如何在android中的Bitmap上绘图?
我试图弄清楚如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
new Canvas(Bitmap 位图)
提供带有Bitmap
的Canvas
,其中将包含绘图操作的结果。您使用
drawBitmap
在Canvas
上绘制的原始Bitmap
永远不会被修改。用户完成每个操作后,您可以:
另一种方法是使用
LayerDrawable
将连续的绘制操作堆叠在一起。您可以想象允许用户禁用已完成的每个单独操作。Use
new Canvas(Bitmap bitmap)
to provide aCanvas
with aBitmap
which will contain the result of your drawing operations.The original
Bitmap
that you draw on yourCanvas
withdrawBitmap
will never be modified.After each operation done by the user you might:
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.您可以在此处查看如何绘制文本的完整指南:
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.