How to draw on bitmap using another bitmap as mask?

僤鯓⒐⒋嵵緔 提交于 2019-12-09 17:41:34

问题


I want to draw on a bitmap using another bitmap as mask. The mask is a black bitmap with a transparent object in it. I want this transparent part to be filled with an arbitrary color and added to my original image. How can this be done?

+

+ blue color =


回答1:


I had to change the masks as described by @Christian. Then, the wanted result could easily be produced:

canvas.drawRect(rect, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawBitmap(mask, 0.0f, 0.0f, paint);



回答2:


If you're setting this to an ImageView, a quick way is to set the background to the gradient drawable, and a blue 'T' with a transparent background as the ImageView's source. Not fancy, but fast and simple!



来源:https://stackoverflow.com/questions/17835435/how-to-draw-on-bitmap-using-another-bitmap-as-mask

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