Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android PorterDuffXfermode on ICS

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)

like image 270
Spotlight Avatar asked Dec 10 '25 20:12

Spotlight


1 Answers

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);
like image 125
Kevin Coppock Avatar answered Dec 12 '25 14:12

Kevin Coppock