I'm trying to use this code but something goes wrong. Any idea?
BitmapData oldData = img.LockBits(new Rectangle(0,0,width,height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
BitmapData newData = newBMP.LockBits(new Rectangle(0,0,width,height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int remain_old = oldData.Stride - width * 4;
int remain_new = newData.Stride - width * 1;
// unsafe block
unsafe
{
byte* currentPosition_Old = (byte*) oldData.Scan0;
byte* currentPosition_New = (byte*) newData.Scan0;
// Standard Deviation
for (int x=0; x<=width; x++)
{
for (int y=0; y<height; y++)
{
currentPosition_New[0] = (byte) currentPosition_Old[0];
currentPosition_Old += 4; // ARGB
currentPosition_New += 1; // indexed
}
currentPosition_Old += remain_old;
currentPosition_New += remain_new;
}
}
img.UnlockBits(oldData);
newBMP.UnlockBits(newData);