J
JLW
Could someone give me a hint on what I goofed up? I can't seem to get this
damned thing to work:
public static bool Brighten(Bitmap b, int nBrightness)
{
// GDI+ return format is BGR, NOT RGB.
Rectangle rect = new Rectangle(0,0,b.Width,b.Height);
BitmapData bmData =
b.LockBits(rect,ImageLockMode.ReadWrite,PixelFormat.Undefined); //This is
the problem
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
int nVal;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y<b.Height;++y)
{
for (int x = 0; x < nWidth; ++x)
{
nVal = (int) (p[0] + nBrightness);
if (nVal < 0) nVal = 0;
if (nVal > 255) nVal = 255;
p[0] = (byte)nVal;
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
Here's the error I get at the Line above (BitmapData bmData ......)
"Additional information: Invalid parameter used."
I can't figure this one out.
Thank in advance,
JLW
damned thing to work:
public static bool Brighten(Bitmap b, int nBrightness)
{
// GDI+ return format is BGR, NOT RGB.
Rectangle rect = new Rectangle(0,0,b.Width,b.Height);
BitmapData bmData =
b.LockBits(rect,ImageLockMode.ReadWrite,PixelFormat.Undefined); //This is
the problem
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
int nVal;
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y<b.Height;++y)
{
for (int x = 0; x < nWidth; ++x)
{
nVal = (int) (p[0] + nBrightness);
if (nVal < 0) nVal = 0;
if (nVal > 255) nVal = 255;
p[0] = (byte)nVal;
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
Here's the error I get at the Line above (BitmapData bmData ......)
"Additional information: Invalid parameter used."
I can't figure this one out.
Thank in advance,
JLW