C#でbyte[]配列をImageに変換する問題を教えてください.
1503 ワード
C# , 320X240,16 , 153600 , g[] ,
byte[] g = new byte[153600];
for (int i = 0; i != g.Length; i++)
{
g[i] = Convert.ToByte(sp.ReadByte()) ;
}
byte[] Image:
public Image ByteArrayToImage(byte[] b)
{
MemoryStream ms = new MemoryStream(b);
Image img = Image.FromStream(ms);
return img;
}
, , Image img = Image.FromStream(ms); “ ”, ?
Image , 。
FromStream jpg,bmp , rgb
Image Bitmap,
byte[] rgb = new byte[153600];// RGB
Bitmap img = new Bitmap(320, 240, PixelFormat.Format24bppRgb);
//
BitmapData data=img.LockBits(
new Rectangle(0,0,img.Width,img.Height),
ImageLockMode.WriteOnly,
PixelFormat.Format24bppRgb);
//
System.Runtime.InteropServices.Marshal.Copy(rgb, 0, data.Scan0, rgb.Length);
img.UnlockBits(data);//
g.DrawImage(img);// Graphics
変換元:http://zhidao.baidu.com/link?url=LNDGTpC7CdagtfU7u1OdE_9MxBIWBXdG_AodVvakdOvXe1Y7B-_EnXgVTIVAQ7lA8KPwupCKRmNakOjyRvhHga
static GCHandle handle; static int scan; static Bitmap pBuffer = null; handle = GCHandle.Alloc(rgbArray, GCHandleType.Pinned) scan = (int)handle.AddrOfPinnedObject(); scan += (height - 1) * stride; pBuffer = new Bitmap(width, height, -stride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, (IntPtr)scan); PictureBox.Image = pBuffer; handle.Free();
変換元:http://tieba.baidu.com/p/2123187152