How to combine two opaque bitmaps into one with alpha channel?

前端 未结 3 1690
栀梦
栀梦 2021-01-22 03:29

I have a PNG file with transparency that I\'m using as OpenGL texture. I load it in Bitmap with BitmapFactory.decodeResource, then upload it to GPU.

3条回答
  •  感动是毒
    2021-01-22 03:46

    Try the following: Iterate through width * height of your two images, and use Bitmap.getPixel(x,y) on each one.

    int alpha = Color.red(grayscaleBitmap.getPixel(x, y)); // grayscale, so any color will do
    int red = Color.red(colorBitmap.getPixel(x, y));
    int green = Color.green(colorBitmap.getPixel(x, y));
    int blue = Color.blue(colorBitmap.getPixel(x, y));
    int mergedColor = Color.argb(alpha, red, green, blue);
    // save mergedColor in an int[]
    

    Then use Bitmap.createBitmap(int[] colors, int width, int height, Bitmap.Config config) to create your new bitmap.

提交回复
热议问题