private static Bitmap CloneImage(BitmapData sourceData)
{
// get source image size
int width = sourceData.Width;
int height = sourceData.Height;
// create new image
Bitmap destination = new Bitmap(width, height, sourceData.PixelFormat);
// lock destination bitmap data
BitmapData destinationData = destination.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadWrite, destination.PixelFormat);
Accord.SystemTools.CopyUnmanagedMemory(destinationData.Scan0, sourceData.Scan0, height * sourceData.Stride);
// unlock destination image
destination.UnlockBits(destinationData);
return destination;
}
}