Android : How do I undo a bitmap which has been drawn to a canvas?

on Friday, January 30, 2015


I am dropping drawables on a canvas like markers, setting the final bitmap to an ImageView. How do I add an undo functionality where I can undo one drawable at a time? Please help.


This is my code:



Bitmap bitmap = ((BitmapDrawable) prescription.getDrawable()).getBitmap();

//Create a new image bitmap and attach a brand new canvas to it
Bitmap tempBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.RGB_565);

Canvas tempCanvas = new Canvas(tempBitmap);

//Draw the image bitmap into the canvas
tempCanvas.drawBitmap(bitmap, 0, 0, null);

Bitmap marker = BitmapFactory.decodeResource(getResources(), R.drawable.check);

//Draw into the canvas
tempCanvas.drawBitmap(marker, x, y, null);

//Attach the canvas to the ImageView
imageView.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));

0 comments:

Post a Comment