drawBitmap to canvas with a transparent bitmap, replace original pixels
Asked Answered
D

0

9

My app lets the user edit an image. The image is edited in "slices": The user selects a portion of the big image to edit (1), the user edits it (2, 3), and then when the user finishes, the edited slice is copied back over the original image (4). You can see the simplified procedure in the following image.

Sample workflow

  • To edit the slice, I create a bitmap of the cropped region, which is the one the user edits (2,3).

  • When the user finishes, I just drawBitmap() the slice into the original image (4). The process is more complex because the original image has a transformation matrix, that I have to invert, etc, but for the sake of simplicity this is enough.

The problem arises when the user clears some pixels in the slice (3). I can't find a proper PorterDuff / Paint mode so the edited slice replaces the portion on the original image, even with transparent pixels. What I want is to get the result depicted at (4)

My best bet so far is to use PorterDuff.SRC, but as you see in the image below, the transparent pixels turn Black in the original image. If I set the paint's color to Transparent, the whole result is 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, the transparent pixels are just ignored. In the second, the transparent pixels are painted black.

Sample result

Demetricedemetris answered 22/11, 2014 at 8:17 Comment(1)
Didn't you find any solution after all of the years? :DSpires

© 2022 - 2024 — McMap. All rights reserved.