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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With