我需要用文件流創建位圖。到目前爲止,我有這個代碼:用文件流創建位圖
using (FileStream bmp = File.Create(@"C:\test.bmp"))
{
BinaryWriter writer = new BinaryWriter(bmp);
int i = 0;
// writer.Write((char*)&fileheader, sizeof(fileheader));
// writer.Write((char*)&infoheader, sizeof(infoheader));
for (int rows = 0; rows < 160; rows++)
{
for (int cols = 0; cols < 112; cols++)
{
writer.Write(CamData[i]);
i++;
}
}
bmp.Close();
}
但我仍然需要頭位置信息的位圖。我的問題是,我不知道如何在C#中實現它們。我知道分辨率(320 x 240),我的像素數據是在ushort數組中給出的16位灰度值。
感謝
我不能使用Bitmap類,因爲我沒有一個字節數組!我有USHORT值 – h0ppel 2011-03-27 13:52:59
使用Bitmap.LockBits()並要求16bpp格式。 – 2011-03-27 14:52:30
當我使用PixelFormat.Format16bppGrayScale時,我總是得到一個gdi +錯誤。其他像素格式運行良好。使用PixelFormat.Format24bppRgb後,我得到這樣的結果:圖片在第一行3次![test.bmp] [1] [1]:http://i.imgur.com/Cls1e.png – h0ppel 2011-03-27 15:39:59