What's wrong with this?

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
 
J

JLW

I found my problem, GDI is saving the image in 24bpp, and the origional
program is saving it as 8bpp, so I need to modify this sucker to save a 8bpp
jpeg.

Sigh

JLW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top