How to draw a raster image on canvas, observing the alpha values ​​of the raster image?

background

I have a basic bitmap that I need to draw other bitmaps on it.

the main bitmap has translucent pixels (pixels with variant values ​​for the alpha channel), so the other bitmaps that are drawn on it must be combined with it, and not completely override the colors.

question

How can I set the canvas for drawing bitmaps on the main bitmap relative to translucent pixels?

note: alpha is not for the entire bitmap / s. it's per pixel.

+4
source share
3 answers

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

+6
source
 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); } 
+4
source
  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 change it to 50 to make it translucent.

0
source

Source: https://habr.com/ru/post/1490517/


All Articles