usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Drawing;
usingSystem.IO;
public BitmapAddHeader(byte[]imageDataDetails)
{
Bitmapbitmap=null;
intlength=imageDataDetails.GetLength(0);
using(MemoryStreamstream=newMemoryStream(length+14))//为头腾出14个长度的空间
{
byte[]buffer=newbyte[13];
buffer[0]=0x42;//Bitmap固定常数
buffer[1]=0x4d;//Bitmap固定常数
stream.Write(buffer,0,2);//先写入头的前两个字节
//把我们之前获得的数据流的长度转换成字节,
//这个是用来告诉“头”我们的实际图像数据有多大
byte[]bytes=BitConverter.GetBytes(length);
stream.Write(bytes,0,4);//把这个长度写入头中去
buffer[0]=0;
buffer[1]=0;
buffer[2]=0;
buffer[3]=0;
stream.Write(buffer,0,4);//在写入4个字节长度的数据到头中去
intnum2=0x36;//Bitmap固定常数
bytes=BitConverter.GetBytes(num2);
stream.Write(bytes,0,4);//在写入最后4个字节的长度
stream.GetBuffer();
stream.Write(imageDataDetails,0,length);//把实际的图像数据全部追加到头的后面
bitmap=newBitmap(stream);//用内存流构造出一幅bitmap的图片
bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);
stream.Close();
returnbitmap;//最后就得到了我们想要的图片了
}
}