簡單來講 就是用了 BitmapData 再用 Marshal.Copy 把byte[]印過去
private Bitmap Load_RGB_img(ref byte[] Camera1_Buffer, int Width, int Height)
{
int Camera_len_Buffer = Width * Height * 3;
Bitmap image0_Source = new Bitmap(
Width, Height,
PixelFormat.Format24bppRgb);
Rectangle rect = new Rectangle(
0, 0, image0_Source.Width, image0_Source.Height);
System.Drawing.Imaging.BitmapData bmpData = image0_Source.LockBits(
rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
image0_Source.PixelFormat);
System.Runtime.InteropServices.Marshal.Copy(
Camera1_Buffer, 0, bmpData.Scan0,
bmpData.Stride * image0_Source.Height);
image0_Source.UnlockBits(bmpData);
return image0_Source;
}
LockBits
跟 UnlockBits
是一對的記得要連在一起用