M
Morten Nielsen
Does anyone have any idea why I can't get a pixel-value of 255 returned in
the code below?
Any color-value from 0 up to 254 is returned correctly, but any
color-component of 255 returns zero. ie. bright white pixel would return
0,0,0 with the function below: The color (234,123,255) returns (234,123,0).
I would have thought that the byte value could hold values from 0..255 and
not only 0..254. At least thats what the C# specs and my common sense tell
me
/// <summary>
/// Gets the color of a 24bit-pixel by using direct access to memory
/// </summary>
/// <param name="x">Row</param>
/// <param name="y">Column</param>
/// <returns>Color of pixel at (row,column)</returns>
public unsafe Color GetPixel(int x, int y)
{
byte* p = (byte *)bmd.Scan0 + y*bmd.Stride + 3*x;
return Color.FromArgb(p[2],p[1],p[0]);
}
where bmd is declared as:
private BitmapData bmd = myBitmap.LockBits(new Rectangle(0, 0,
myBitmap.Width, myBitmap.Height), ImageLockMode.ReadWrite,
myBitmap.PixelFormat);
I have checked that (myBitmap.PixelFormat==PixelFormat.Format24bppRgb) is
true.
Any help or ideas are appreciated
Regards
/Morten Nielsen
www.dotnetgis.net
the code below?
Any color-value from 0 up to 254 is returned correctly, but any
color-component of 255 returns zero. ie. bright white pixel would return
0,0,0 with the function below: The color (234,123,255) returns (234,123,0).
I would have thought that the byte value could hold values from 0..255 and
not only 0..254. At least thats what the C# specs and my common sense tell
me
/// <summary>
/// Gets the color of a 24bit-pixel by using direct access to memory
/// </summary>
/// <param name="x">Row</param>
/// <param name="y">Column</param>
/// <returns>Color of pixel at (row,column)</returns>
public unsafe Color GetPixel(int x, int y)
{
byte* p = (byte *)bmd.Scan0 + y*bmd.Stride + 3*x;
return Color.FromArgb(p[2],p[1],p[0]);
}
where bmd is declared as:
private BitmapData bmd = myBitmap.LockBits(new Rectangle(0, 0,
myBitmap.Width, myBitmap.Height), ImageLockMode.ReadWrite,
myBitmap.PixelFormat);
I have checked that (myBitmap.PixelFormat==PixelFormat.Format24bppRgb) is
true.
Any help or ideas are appreciated
Regards
/Morten Nielsen
www.dotnetgis.net