private Bitmap BildSW(Bitmap bmp)
{
int numBytes = bmpData.Stride * bmp.Height;
byte[] rgbValues = new byte[numBytes];
int tmpSW;
PixelFormat pxf = PixelFormat.Format24bppRgb;
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
IntPtr ptr = bmpData.Scan0;
Marshal.Copy(ptr, rgbValues, 0, numBytes);
for(int counter = 0; counter < rgbValues.Length; counter+=3)
{
tmpSW = rgbValues[counter];
tmpSW += rgbValues[counter+1];
tmpSW += rgbValues[counter+2];
tmpSW /= 3;
rgbValues[counter] = rgbValues[counter+1] = rgbValues[counter+2] = Convert.ToByte(tmpSW);
}
Marshal.Copy(rgbValues, 0, ptr, numBytes);
bmp.UnlockBits(bmpData);
return bmp;
}