Page 1 of 1
Finding the alpha value of a pixel
Posted: 2005-09-18 01:28am
by Sarevok
If you know the red, green, blue components of a pixel is there a way to find the alpha value of that pixel ? One program I am working on needs to do that. My own alpha value extractor failed and I am not good with Photo editing software.
Posted: 2005-09-18 03:41am
by Jawawithagun
From a pixel already drawn onscreen? Sorry, no can do.
From an image file? See where the Alpha Channel is stored.
Posted: 2005-09-18 09:31am
by Dooey Jo
If you know the colour values of the underlying pixel, finding the alpha value would be trivial. Because R = R0 * (1 - a) + R1 * a.
So a = (R - R0) / (R1 - R0)
You might have to scale a (or the result), because it will probably range from 0 - 100 or 0 - 255, and not 0 - 1. R can be the any of the three colours, or all of them. Unless some fancy blending technique is in use, the result will be the same, no matter which you use. If there is some fancy blending technique, you will have to replace the formula, with that of the blending technique...
Of course, if you don't know the underlying pixel, then it gets a little harder... What exactly is it you are trying to do? Get the alpha value from a file, or from the screen?