Adam Lee
Adam Lee

Reputation: 25778

How do I know if an image is "Premultiplied Alpha"?

I heard that only premultiplied alpha is needed when doing layer blending etc. How do I know if my original image is premultiplied alpha?

Upvotes: 6

Views: 10654

Answers (2)

keaukraine
keaukraine

Reputation: 5364

Android Bitmap stores images loaded from PNG with premultiplied alpha. You can't get non-premultiplied original colours from it in usual way.

In order to load images without RGB channels being premultiplied I have to use 3rd party PNGDecoder from here: http://twl.l33tlabs.org/#downloads

Upvotes: 4

PeterT
PeterT

Reputation: 8284

You can't.

The only thing that you can check is if it's not premultiplied. To do it go over all the pixels and see if there is a color-value that has a higher value than the alpha would permit if(max(col.r,col.g,col.b) > 255*alpha)//not premul. Any other cases are ambiguous and could or could not be premultiplied. Your best guess is probably to assume that they aren't as that's the case for most PNGs.

Edit: actually, not even the code that I posted would work as there are a lot of PNGs out there with white matte, so the image would have to include parts that have an alpha of 0 to determine the matte color first.

Upvotes: 12

Related Questions