Masked bitmap on canvas with transparent activity

醉酒当歌 提交于 2019-12-25 03:42:56

问题


I implemented custom ShowCase for activity

I am trying to draw on canvas mask: http://i.stack.imgur.com/u23kQ.png

Following this code:

mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

    // draw solid background
    mCanvas.drawColor(mMaskColour);

    // Prepare eraser Paint if needed
    if (mEraser == null) {
        mEraser = new Paint();
        mEraser.setColor(0xFFFFFFFF);
        mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mEraser.setFlags(Paint.ANTI_ALIAS_FLAG);
    }

    // draw (erase) shape
   // mShape.draw(mCanvas, mEraser, mXPosition, mYPosition, mShapePadding);

    mCanvas.drawBitmap(cBitmap,mXPosition,mYPosition,mEraser);

    // Draw background
    canvas.drawBitmap(mBitmap, 0, 0, null);

But it appears like this:

http://i.stack.imgur.com/MhcOt.png


回答1:


I solve this

 Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        mCanvas.drawBitmap(cBitmap,mXPosition,mYPosition,paint);
       // mShape.draw(canvas, mEraser, mXPosition, mYPosition, mShapePadding);
        // Draw the bitmap on our views  canvas.
        canvas.drawBitmap(mBitmap, 0, 0, null);


来源:https://stackoverflow.com/questions/33914555/masked-bitmap-on-canvas-with-transparent-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!