How to apply dynamic alpha mask to a Text on Android

ε祈祈猫儿з 提交于 2019-12-03 00:02:17

Try creating your source and mask bitmaps separately. Most of the examples I have seen involve using two bitmaps and using drawBitmap to perform the masking.

I use PorterDuff.Mode.DST_IN for the paint, then draw the source image (with no paint) followed by the mask image (with the paint). Something like this:

        Bitmap bitmapOut = Bitmap.createBitmap(sizeX, sizeY,
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapOut);

        Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        xferPaint.setColor(Color.BLACK);

        xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

        canvas.drawBitmap(sourceImage, 0, 0, null);
        canvas.drawBitmap(alphaMask, 0, 0, xferPaint);

At this point, bitmapOut contains my masked image.

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