Search code examples
androidviewbitmapandroid-canvasundo-redo

Android Bitmap Undo Redo Effect


Create Canvas with multiple tools like Pencil,eraser,Line,oval,triangle,square ,undo,redo etc.

Undo,Redo not working.

  @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
            super.onSizeChanged(w, h, oldw, oldh);

            mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBitmap);

}

Solution

  • I disagree with the first answer, store a bitmap is very expensive.

    what you should store is action itself.you can create a new class call Action, and store the drawing path, Paint style,etc.and when user click the redo button, perform the action on the bitmap.

    I wrote a demo about paintboard, it currently support only undo action,but with the actions store in a List,you can easily add redo feature to it.the address is PaintView.