От: | FLUID | http://yuriy-okhmat.blogspot.com/ | |
Дата: | 22.12.05 10:25 | ||
Оценка: | 2 (1) |
public Image EqualizeImage(Bitmap bmp, int nTreshold)
{
BitmapData bmpData = bmp.LockBits(new Rectangle(0,0,
bmp.Width,bmp.Height),ImageLockMode.ReadWrite,
PixelFormat.Format24bppRgb);
int stride = bmpData.Stride;
System.IntPtr Scan0 = bmpData.Scan0;
try
{
unsafe
{
byte *p = (byte *)(void *)Scan0;
int nOffset = stride - bmp.Width*3;
int nWidth = bmp.Width*3;
for(int y = 0; y < bmp.Height; ++y)
{
for(int x = 0; x < nWidth; ++x)
{
if(p[0] >= nTreshold)
p[0] = 255;
if(p[0] < nTreshold)
p[0] = 0;
++p;
}
p += nOffset;
}
}
}
catch(Exception e)
{
this._strErrorString = e.Message;
}
bmp.UnlockBits(bmpData);
Image testImg = Image.FromHbitmap(bmp.GetHbitmap());
return testImg;
}