0
我有位圖,我正在應用兩個遮罩。當我在位圖的右側應用遮罩時,它可以正常工作,但之後當我在同一位圖的底部應用遮罩時,由於遮罩,我在位圖上再次出現一個區域。我試圖用下面的圖解釋這個問題。圈出的區域造成了問題。即使在重新屏蔽後,我仍希望該區域保持透明。Android位圖遮罩
這裏是我的遮蔽函數的代碼剪斷。
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
.......
public void setRightMask(MyBitmap bmp, Type type) {
int maskIndex = -1;
switch(type){
case CONCAVE:
maskIndex = 0;
break;
case CONVEX:
maskIndex = 6;
break;
}
Bitmap result = Bitmap.createBitmap((int)bmp.getWidth(), (int)bmp.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(bmp.getBmp(), 0, 0, null);
canvas.drawBitmap(masks[maskIndex].getBmp(), bmp.getWidth() - masks[maskIndex].getBmp().getWidth(), 0, paint);
bmp.setBmp(result);
}
public void setBottomMask(MyBitmap bmp, Type type) {
int maskIndex = -1;
switch(type){
case CONCAVE:
maskIndex = 1;
break;
case CONVEX:
maskIndex = 7;
break;
}
Bitmap result = Bitmap.createBitmap((int)bmp.getWidth(), (int)bmp.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(result);
canvas.drawBitmap(bmp.getBmp(), 0, 0, null);
canvas.drawBitmap(masks[maskIndex].getBmp(), 0, bmp.getHeight() - masks[maskIndex].getBmp().getHeight(), paint);
bmp.setBmp(result);
}