ICS上的Android PorterDuffXfermode

时间:2012-07-19 20:50:19

标签: android android-4.0-ice-cream-sandwich paint

有一些代码可以在Android 2.2上完美运行,但在Android 4中只生成黑色视图。那是onDraw方法:

//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:遮罩和聚光灯是两个位图。

不设置Xfermode绘制两个位图被绘制(我的范围不正确,但绘制在正确的位置并且尺寸合适)

1 个答案:

答案 0 :(得分:7)

您需要为该特定View禁用硬件加速。有关详细信息,请参阅Hardware Acceleration - Unsupported Drawing Operations部分,以及有关如何有选择地禁用硬件加速的信息。例如:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);