As what was stated on the header I want to implement either a "paint" or "eraser" function whichever feature more convenient for user to edit paint/censor unwanted parts of a photo displayed on a imageview before uploading it to a server in the edited format and a redo function if user makes a mistake while editing?

How do I come about doing it, I've read relevant topics on Canvas, or FingerPaint but still puzzled on how to implement it based on the scenario in this link here? Thanks for any help rendered!

idImage = (ImageView)findViewById(R.id.idImage);   
Bitmap bitmap = null;
bitmap = ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
idImage.setImageBitmap(bitmap);

Dani AI

Generated

Note for : a reliable pattern is to keep the photo untouched in the ImageView and add a transparent, bitmap-backed custom DrawingView on top. The DrawingView records touch input as Paths (one Path per stroke) and renders them onto an off-screen ARGB_8888 bitmap via a Canvas. For a paint tool the View draws strokes with a normal Paint. For an eraser the View draws using a Paint with an Xfermode that clears pixels (PorterDuff.Mode.CLEAR or DST_OUT) so the overlay becomes transparent and the photo shows through. Touch coordinates must be mapped from view-space into bitmap-space when the ImageView scales the photo (use the ImageView matrix inverse).

Important snippets (concepts only):

// map touch coords to bitmap coords
Matrix inv = new Matrix();
imageView.getImageMatrix().invert(inv);
float[] pts = new float[]{touchX, touchY};
inv.mapPoints(pts);
int bx = Math.round(pts[0]), by = Math.round(pts[1]);
// eraser paint (draw onto an ARGB_8888 layer)
Paint eraser = new Paint();
eraser.setAntiAlias(true);
eraser.setStyle(Paint.Style.STROKE);
eraser.setStrokeCap(Paint.Cap.ROUND);
eraser.setStrokeWidth(eraseSize);
eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

Undo/redo: store stroke operations (Path + Paint attributes + mode) in a list. Undo = remove last op and replay the list onto a fresh empty layer. This is much more memory-friendly than snapshotting full bitmaps; if snapshots are used, limit count and downscale them.

Cautions and tips: disable hardware acceleration for the DrawingView when using Xfermode (setLayerType(LAYER_TYPE_SOFTWARE, null)), keep all work that encodes/compresses bitmaps off the UI thread, scale large photos to the view size to avoid OOM, and use ARGB_8888 for alpha-aware erasing. To save/upload, flatten original + overlay into a single bitmap (draw original then overlay) and compress (JPEG/PNG) in a background task.

bump

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.