Make a specific area of ​​the bitmap transparent when you touch & # 8594; again

I am trying to achieve the same results as in the stream: Make a certain area of ​​the bitmap transparent to the touch . I adhere to the code provided in this answer: Lumis answer and according to SteD this solution should work.

Unfortunately, it doesn’t work for me (as well as for another user: Making a certain area of ​​the bitmap transparent when it doesn’t work, it draws a black circle ), I just get a black circle. I tried a lot, but did not decide. Make the background transparent in accordance with the proposal from the second stream does not matter.

After many experiments, I found that transparency works when I set this

android:theme="@android:style/Theme.Translucent"

in my AndroidManifest.xml I see everything under my application, that is, on the desktop. I went through the code many times and could not see the obvious error, only the reason I think about is the reason that this is order Z, but the bitmaps and canvas do not support z orders. Order Z is performed by drawing in a specific order (which is correct in this code).

Is this some weird optimization example in android code, or am I missing something in the android manifest file?

+5
source share
2 answers

Finally, I found a solution that works:

@Override
public void onDraw(Canvas canvas){
    super.onDraw(canvas);

    //draw background
    canvas.drawBitmap(bgr, 0, 150, null);
    //copy the default overlay into temporary overlay and punch a hole in it                          
    c2.drawBitmap(overlayDefault, 0, 0, null); //exclude this line to show all as you draw
    c2.drawCircle(X, Y, 80, pTouch);
    //draw the overlay over the background
    //canvas.drawBitmap(overlay, 0, 0, null);

    Paint new_paint = new Paint(/*Paint.ANTI_ALIAS_FLAG*/);
    new_paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));
    canvas.drawBitmap(overlay, 0, 0, new_paint);
}

, . xfermodes : - Android android Xfermodes : Xfermodes

, , xfermode , bean ( Z), . Z .

- , , , .

.

+6

onDraw():

public void onDraw(Canvas canvas){
        super.onDraw(canvas);
        canvas.drawColor(Color.TRANSPARENT);
        canvas.drawBitmap(bgr, 0, 0, null);

        c2.drawCircle(X, Y, 10, pTouch);
        Paint new_paint = new Paint(/*Paint.ANTI_ALIAS_FLAG*/);
        new_paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));
        canvas.drawBitmap(overlay, 0, 0, new_paint);
    }

, ! ,

+2

All Articles