My application allows the user to edit the image. The image was edited in βslicesβ: the user selects part of a large image for editing (1), the user edits it (2, 3), and then, when the user finishes, the edited fragment is copied back to the original image (4). You can see the simplified procedure in the following figure.

To edit a slice, I create a bitmap image of the cropped area that the user edits (2,3).
When the user finishes, I just drawBitmap() slice into the original image (4). The process is more complicated, because the original image has a transformation matrix, which I have to invert, etc., but for simplicity this is enough.
The problem occurs when the user clears some pixels in the slice (3) . I cannot find the correct PorterDuff / Paint mode, so the edited fragment replaces part of the original image even with transparent pixels. I want to get the result depicted in (4)
It is best to use PorterDuff.SRC , but as you see in the image below, the transparent pixels become black in the original image. If I set the color to Transparent, the whole result will be black.
mBlitPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); mImageCanvas.drawBitmap(mArenaBitmap, invertedMatrix, mBlitPaint);
I also tried SRC_OVER and even mImageCanvas.drawARGB (0xff,0,0,0), , but no luck. In the first case, transparent pixels are simply ignored. In the second, transparent pixels are painted black.

source share