How does Android apply the alpha channel when using copyPixelsToBuffer?

Related topic (no solution): Raw Data Access in ARM_8888 Android Bitmap

In short: when using copyPixelFromBuffer, copyPixelsToBufferAndroid has already applied the alpha channel on RGB channels.

I need to convert it to the original ARGB value and vice versa. I do not know how Android applies it. Could you tell me the formula?

+2
source share
1 answer

Android stores bitmap data in alpha-multiplied form. In other words, the alpha value is not applied when copying data, it is applied all the time.

, , :

redPremultiplied   = red   * normalizedAlpha
greenPremultiplied = green * normalizedAlpha
bluePremultiplied  = blue  * normalizedAlpha
alphaPremultiplied = alpha

red             = <value between 0 and 255>
green           = <value between 0 and 255>
blue            = <value between 0 and 255>
alpha           = <value between 0 and 255>
normalizedAlpha = alpha / 255

, :

red   = redPremultiplied   / normalizedAlpha
green = greenPremultiplied / normalizedAlpha
blue  = bluePremultiplied  / normalizedAlpha
alpha = alphaPremultiplied

Alpha = 0! , , Bitmap.copyPixelsToBuffer() Bitmap.copyPixelsFromBuffer() , . Bitmap.getPixels() Bitmap.setPixels(), API , . , un-premultiplying , .

+1

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


All Articles