有人請幫助我,我不知道哪裏會出錯,我已經嘗試了一切可能的事情在這裏,但相同的黑色補丁出現 ..不知道哪裏即將出錯..使圖像的一部分透明使用PorterDuffXfermode
第一個圖像直接在畫布上繪製,然後在畫布對象c2上,繪製overlayDefault圖像,然後將繪畫應用到它,然後回到原始畫布上,繪製我獲得的overlay_mutable後使用
overlay_mutable = overlayDefault.copy(Config.ARGB_8888, true);
但仍然繪製圖像,但只點擊一個黑色補丁顯示和底下ing圖像沒有看到!
public class PartTransparent extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new TouchView(this));
}
class TouchView extends View{
Bitmap bgr;
Bitmap overlayDefault;
Bitmap overlay_mutable;
Paint pTouch;
int X = -100;
int Y = -100;
Canvas c2;
public TouchView(Context context) {
super(context);
bgr = BitmapFactory.decodeResource(getResources(),R.drawable.mah_grp_pic);
overlayDefault = BitmapFactory.decodeResource(getResources(),R.drawable.z_oceanblue);
overlay_mutable = overlayDefault.copy(Config.ARGB_8888, true); // convert to ARGB_8888 format,only den can it be put on canvas in next line..
c2 = new Canvas();
c2.setBitmap(overlay_mutable);
c2.drawBitmap(overlayDefault, 0, 0, null);
pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
pTouch.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
pTouch.setAlpha(0);
pTouch.setColor(Color.TRANSPARENT);
pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); // Blur modes
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;
}
case MotionEvent.ACTION_MOVE: {
X = (int) ev.getX();
Y = (int) ev.getY();
invalidate();
break;
}
case MotionEvent.ACTION_UP:
break;
}
return true;
}
@Override
public void onDraw(Canvas canvas){
canvas.drawBitmap(bgr, 0, 0, null);
//copy the default overlay into temporary overlay and punch a hole in it
c2.drawBitmap(overlayDefault, 0, 0, null); //exclude this line to show all as you draw
c2.drawCircle(X, Y, 80, pTouch);
//draw the overlay over the background
canvas.drawBitmap(overlay_mutable, 0, 0, null);
super.onDraw(canvas);
}
}
無論如何,我找到了解決方案,而不是「overlay_mutable = overlayDefault.copy(Config.ARGB_8888,true);」 使用overlay_mutable = Bitmap.createBitmap(width,height,Config.ARGB_8888); – Mahesh 2012-03-23 13:58:20