如何在Android中吸取位图? [英] How to draw on Bitmap in android?

查看:100
本文介绍了如何在Android中吸取位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何利用android的位图,并保持这些变化的位图的副本撤消功能。

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?

或如何得到位图后,它被画在与画布(我想preserve一叠位图与绘图画布应用的变化)?也许我会对此完全错误的。

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.

推荐答案

使用<一个href="http://developer.android.com/reference/android/graphics/Canvas.html#Canvas%28android.graphics.Bitmap%29"><$c$c>new帆布(位图位图) 提供了画布位图这将包含绘图操作的结果。

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

位图,你利用你的画布 drawBitmap 将永远不会被修改。

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

由用户来完成每一个操作之后,您可能:

After each operation done by the user you might:

  • 保存在内存中进行的操作的列表
  • 在保存中间结果到外部存储与Bitmap.com preSS

另一种方法可以是使用一个<一href="http://developer.android.com/intl/fr/reference/android/graphics/drawable/LayerDrawable.html"><$c$c>LayerDrawable堆叠在彼此的顶部连续绘图操作。你可以想像,允许用户禁用每个单独的操作完成。

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.

这篇关于如何在Android中吸取位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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