public static unsafe byte[,] ImageToBytes(Bitmap image)
{
//Bitmap bitmap = ((Bitmap)image.Clone());
int w = image.Width;
int h = image.Height;
byte[,] bytes = new byte[w, h];
Rectangle rectangle = new Rectangle(0, 0, w, h);
// 将图片位图区域进行锁定
BitmapData mapdata = image.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
byte* pixpoint = (byte*)mapdata.Scan0 + 1;
int iStride = mapdata.Stride;
byte* index;
for (int i = 0; i < w; i++)
{
index = pixpoint + i * 3;
for (int j = 0; j < h; j++)
{
bytes[i, j] = *(index + j * iStride);
}
}
// 将位图内存区域进行解锁
image.UnlockBits(mapdata);
return bytes;
}