2012-07-19 3 views
3

Il existe un code qui fonctionne parfaitement sur Android 2.2, mais dans Android 4 ne produit qu'une vue en noir. C'est la méthode onDraw:Android PorterDuffXfermode sur ICS

//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: masque et projecteur sont deux bitmap.

Sans réglage Xfermode peindre les deux bitmap sont tirées (à tort pour ma portée, mais tiré au bon endroit et à la bonne taille)

Répondre

7

Vous devez désactiver l'accélération matérielle pour ce View particulier. Reportez-vous à la section Hardware Acceleration - Unsupported Drawing Operations pour plus de détails et pour savoir comment désactiver l'accélération matérielle de manière sélective. Par exemple:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
+0

Merci beaucoup, cela a fonctionné! – Spotlight