|
1金钱
这是我写的客户端发来的图像数据转换成图片的函数,为什么转化后的图片在picturebox上显示,正好是原图片旋转了90度
public static Image byteArrayToImage(Byte[] bt)
{
byte[] raw_data = new byte[640 * 480 * 3];
for (int i = 0; i < bt.Length; i++)
{
raw_data[i] = bt[i];
raw_data[i + 1] = bt[i];
raw_data[i + 2] = bt[i];
}
GCHandle hObject = GCHandle.Alloc(raw_data, GCHandleType.Pinned);
IntPtr pObject = hObject.AddrOfPinnedObject();
if (hObject.IsAllocated)
{
hObject.Free();
}
BitmapData bmpData = new BitmapData();
bmpData.Width = 640;
bmpData.Height = 480;
bmpData.Scan0 = pObject;
bmpData.PixelFormat = PixelFormat.Format24bppRgb;
bmpData.Stride = 640;
Bitmap bitmap = new Bitmap(bmpData.Width, bmpData.Height, bmpData.Stride, bmpData.PixelFormat, bmpData.Scan0);
return bitmap;
}
|
|