有一些代码在 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 来绘制两个位图(对于我的范围不正确,但绘制在正确的位置和正确的大小)