Problem with .SetPixel

Oct 28, 2011 at 9:09 AM

There are 5 different ways to use .SetPixel

I have a problem with the one that takes these arguments:  int x, int y, byte a, Color color

 

 byte alfa = 1;   // I tried many different values from 0-255
bmp.SetPixel(pixelpoint.X, pixelpoint.Y, pixelpoint.COLOR);     -> works
bmp.SetPixel(pixelpoint.X, pixelpoint.Y, alfa, pixelpoint.COLOR);   -> doesnt work

 

Am I doing something wrong or is there something wrong with the code?

Coordinator
Oct 28, 2011 at 9:38 AM

I just checked the code in the library. It's exactly the same implementation. 

Make sure you set pixelpoint.Color.A = alfa before using the method which only takes the color bmp.SetPixel(pixelpoint.X, pixelpoint.Y, pixelpoint.COLOR); Otherwise you can'T compare the results.

 

- Rene Schulte

Oct 28, 2011 at 9:38 AM
Edited Oct 28, 2011 at 9:56 AM

I'm sorry, I wasnt paying attention. My color was an integer.

Coordinator
Oct 28, 2011 at 10:12 AM

Just use SetPixeli. It's the equivalent to GetPixeli.

If you need to change the alpha value of the integer color you got from GetPixeli, just do the following bit fiddeling:

pixelpoint.COLOR = unchecked((pixelpoint.COLOR & 0x00FFFFFF) | (alpha << 24));

 

- Rene Schulte

Oct 28, 2011 at 11:31 AM

Wow, excellent. I love you man! :-)