根据触摸输入擦除位图部件

时间:2018-07-03 11:57:14

标签: android bitmap

在这里,我有两个位图,一个位图掩盖了另一个。我要寻找的是基于触摸输入擦除前景位图的某些部分;但是它不会使背景在擦除时可见,而是会擦除两个位图,而不仅仅是前景位图。

您能指出我要去哪里了吗

  public ColorPopView(Context context) {
    super(context);
    init(context);
}


private void init(Context context) {

   if (android.os.Build.VERSION.SDK_INT >= 11)
    {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    bgr = BitmapFactory.decodeResource(getResources(),R.drawable.header1);
    overlayDefault = BitmapFactory.decodeResource(getResources(),R.drawable.header2);
    overlay = BitmapFactory.decodeResource(getResources(),R.drawable.header2).copy(Bitmap.Config.ARGB_8888, true);
    c2 = new Canvas(overlay);

    eraserPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    eraserPaint.setColor(Color.TRANSPARENT);
    eraserPaint.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
}


@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){
    super.onDraw(canvas);

    //draw background
    canvas.drawBitmap(bgr, 0, 0, null);
    //copy the default overlay into temporary overlay and punch a hole in it
    c2.drawCircle(X, Y, 80, eraserPaint);
    //draw the overlay over the background
    canvas.drawBitmap(overlay, 0, 0, null);

}

0 个答案:

没有答案