Translucent Image
I know I can use GDI+ to create translucent images and it will do the rest for me. But that's not what I want, I would like to know the way to determine the color.
Thanks in advance.
I know I can use GDI+ to create translucent images and it will do the rest for me. But that's not what I want, I would like to know the way to determine the color.
Thanks in advance.
You need to Call GetPixel(int x, int y) method on a Bitmap to get the color at a specific X and Y coordinates, See Here:
Bitmap myBitmap = new Bitmap("hello.jpg");
Color pixelColor = myBitmap.GetPixel(2, 2);
pixelColor will tell you what color is at 2 and 2 co-ordinates!!!
Cheers ;-)
The easiest way is to draw the images and get the resulting color, as suggested. If instead you want calculate the result without drawing, I think the formula is something as follows:
Assume we have two pixels, one with components a, r, g, b and we want to overlap another with components A, R, G, B.
The result should be something like:
Alpha = A + (int)((256 - A) / 256 * a));
Red = (int)(R*A / Alpha) + (int)(r*(Alpha - A)/Alpha);
Green = (int)(G*A/Alpha) + (int)(g*(Alpha - A)/Alpha);
Blue = (int)(B*A/Alpha) + (int)(b*(Alpha - A)/Alpha);
I extrapolated this formula by trial and error, so it might be not perfect, but it worked for all the tests I made.
(Please optimize the formula when you implement it!)
HTH
--mc