How to draw a bitmap on a canvas, respecting alpha values of the bitmap?

点点圈 提交于 2019-12-01 06:40:36

Canvas.setXfermode(Xfermode xfermode). There are a number of Xfermodes you can choose.

Desmond Yao
public void putOver(Bitmap master, Bitmap alphaBitmap){
    Canvas canvas = new Canvas(matter);
    Paint paint = new Paint();
    paint.setXferMode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER));
    canvas.drawBitmap(left, top, left+alphaBitmap.width, left+alphaBitmap.height, paint);
}
    public Bitmap PutoverChange(Bitmap all, Bitmap scaledBorder) {
    Paint paint = new Paint();
    final int width = change.getWidth();
    final int height = change.getHeight();
    patt = Bitmap.createScaledBitmap(change, width, height, true);
    Bitmap mutableBitmap = patt.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    scaledBorder = Bitmap.createScaledBitmap(border, width, height, true);
    paint.setAlpha(100);
    canvas.drawBitmap(scaledBorder, 0, 0, paint);
    return mutableBitmap;

}

here the transparency is 100. you can modify it to 50 so it becomes semi transparent.

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