opacity map on bitmap android -


i have 2 bitmaps, 1 wallpaper image , another, black , white image contain alpha information. want apply alpha information wallpaper image.

now know can change opacity this:

img.setopacity(50); 

but sets alpha of whole bitmap, not want. want advanced way set alpha of image based on black , white source.

you want bitmap.setpixel. example, assuming bitmaps same size:

bitmap a,b;//initialized - b&w image, b normal image  (int x = 0; x < a.width(); x++) {     (int y = 0; y < a.height(); y++)     {         int color = b.getpixel(x, y);         int red = (color >> 16) & 0xff;         int green = (color >> 8) & 0xff;         int blue = (color >> 0) & 0xff;         if (a.getpixel(x, y) == color.white)             b.setpixel(x, y, color.argb(0.5, red, green, blue));//alpha = 0.5         else             b.setpixel(x, y, color.argb(1, red, green, blue));//alpha = 1     } } 

Comments