there is some code that works perfectly on Android 2.2, but in Android 4 produces only a black view. That is the onDraw method:
//Object initialization
Paint paint=new Paint();
PorterDuffXfermode exclude=new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT);
paint.setAntiAlias(true);
paint.setDither(true);
//The dimensions are OK and they are at the center of the screen
canvas.drawBitmap(mask, screenWidth / 2 - pixelsToSp(100), screenHeight / 2 - pixelsToSp(100), paint);
paint.setXfermode(exclude);
//PS:targetRect is a portion of screen
canvas.drawBitmap(source, null, targetRect, p);
paint.setXfermode(null);
PS: mask and spotlight are two bitmap.
Without setting Xfermode to paint the two bitmap are drawn (incorrectly for my scope, but drawn in the right place and with the right size)
You need to disable Hardware Acceleration for that particular View. See the Hardware Acceleration - Unsupported Drawing Operations section for more details, and also for information on how to disable Hardware Acceleration selectively. For example:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With