private byte[] Bitmap2pic_bgr_arr(Bitmap b, int length)
{
PixelFormat eFormat = PixelFormat.Format24bppRgb;
Rectangle rcSrcLock = new Rectangle(0, 0, b.Width, b.Height);
BitmapData rSrcBd = b.LockBits(rcSrcLock, ImageLockMode.ReadOnly, eFormat);
int nLineBytes = b.Width * 3;
lock (b)
{
byte[] pic_bgr_arr = new byte[length];
int width = b.Width;
int height = b.Height;
unsafe
{
for (int j = 0; j < height; j++)
{
byte* pSrc = (byte*)(rSrcBd.Scan0) + j * rSrcBd.Stride;
for (int i = 0; i < nLineBytes; i++)
{
pic_bgr_arr[j * nLineBytes + i] = pSrc[i];
}
}
}
b.UnlockBits(rSrcBd);
return pic_bgr_arr;
}
}
public Bitmap pic_bgr_arr2Bitmap(byte[] pic_bgr_arr, int height, int width)
{
Bitmap b = new Bitmap(width, height);
PixelFormat eFormat = PixelFormat.Format24bppRgb;
Rectangle rcSrcLock = new Rectangle(0, 0, b.Width, b.Height);
BitmapData rSrcBd = b.LockBits(rcSrcLock, ImageLockMode.WriteOnly, eFormat);
int nLineBytes = b.Width * 3;
unsafe
{
for (int j = 0; j < height; j++)
{
byte* pSrc = (byte*)(rSrcBd.Scan0) + j * rSrcBd.Stride;
for (int i = 0; i < nLineBytes; i++)
{
pSrc[i] = pic_bgr_arr[j * nLineBytes + i];
}
}
}
b.UnlockBits(rSrcBd);
return b;
}