Interest Ask. My theoretical plan:
You have 2 bitmaps, an “erased” bitmap and a “hidden” bitmap. Erasing pixels from an existing bitmap is not possible, since the Bitmap in Android is immutable . Therefore, instead of erasing pixels from the “erased” bitmap to show the bitmap below, first draw the “erased” bitmap. Next, create a blank, the modified bitmap . Flip all the pixels in the “hidden” bitmap, showing only where the “erased” bitmap was “erased”.
Bitmap mutableBitmap = Bitmap.create(erasableBitmap.getWidth(),erasableBitmap.getHeight(), Bitmap.Config.ARGB_8888); for(Pixel erasedPixel : erasedList) { mutableBitmap.setPixel(x,y, hiddenBitmap.getPixel(erasedPixel.x, erasedPixel.y)); } ... // in a different file class Pixel{ int x, y; }
you will need to fill in the erasedList yourself.
Once you're done, draw on the canvas like this:
canvas.drawBitmap(0,0,eraseableBitmap); canvas.drawBitmap(0,0,mutableBitmap);
make sure you first draw a “erasable” raster map so that it is drawn with new pixels.
If you need help figuring out how to set erased pixels, let me know in the comments and I will help you.
EDIT
To determine which pixels the user tried to erase: in your opinion, capture the onTouch event and you will get the coordinates where the user touched the screen. Save this for any map or hash table, and you should be fine. Create a Pixel object and add it to the global Pixel List
.
EDIT 2
To increase the size of the “scratch”, what you need to do is a little complicated. You need to somehow create an area around the x, y point, affected just like the erased one. A circle would be perfect, but it would be easier to use a square.
for(Pixel erasedPixel: erasedList) { //it actually more complicated than this, since you need to check for boundary conditions. for(int i = -SQUARE_WIDTH/2; i < SQUARE_WIDTH/2; i++){ for(int j = -SQUARE_WIDTH/2; j < SQUARE_WIDTH/2; j++){ mutableBitmap.setPixel(erasedPixel.x+i, erasedPixel.y+j, hiddenBitmap.getPixel(erasedPixel.x+i, erasedPixel.y+j)); } } }