private void SaveasHisFile(string hisPath, List <ushort[, ]> dataList, int intergrationTime) { int NrOfFrames = dataList.Count; int row = dataList[0].GetLength(0); int col = dataList[0].GetLength(1); HisHeader h = new HisHeader(); h.FileID = 0x7000; h.HeaderSize = 68; h.HeadVerdion = 100; h.FileSize = (uint)(32 + 68 + NrOfFrames * row * col * sizeof(ushort)); h.ImageHeaderSize = 32; h.ULX = 1; h.BRX = (short)col; h.ULY = 1; h.BRY = (short)row; h.NrOfFrames = (short)NrOfFrames; h.Correction = 1; try { h.IntegrationTime = (uint)(intergrationTime * 1000); } catch (System.Exception ex) { h.IntegrationTime = 1000 * 1000; } h.TypeOfNumbers = 4; h.X = new byte[34]; h.ImageHeader = new byte[32]; HisObject.SaveDataToHIS(ref h, dataList, hisPath); }
public static void SaveDataToHIS(ref HisHeader header, List <ushort[, ]> dataList, string fname) { if (!fname.EndsWith(".his")) { fname += ".his"; } FileInfo finfo = new FileInfo(fname); if (!finfo.Directory.Exists) { finfo.Directory.Create(); } FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write); fs.Write(BitConverter.GetBytes(header.FileID), 0, 2); fs.Write(BitConverter.GetBytes(header.HeaderSize), 0, 2); fs.Write(BitConverter.GetBytes(header.HeadVerdion), 0, 2); fs.Write(BitConverter.GetBytes(header.FileSize), 0, 4); fs.Write(BitConverter.GetBytes(header.ImageHeaderSize), 0, 2); fs.Write(BitConverter.GetBytes(header.ULX), 0, 2); fs.Write(BitConverter.GetBytes(header.ULY), 0, 2); fs.Write(BitConverter.GetBytes(header.BRX), 0, 2); fs.Write(BitConverter.GetBytes(header.BRY), 0, 2); fs.Write(BitConverter.GetBytes(header.NrOfFrames), 0, 2); fs.Write(BitConverter.GetBytes(header.Correction), 0, 2); fs.Write(BitConverter.GetBytes(header.IntegrationTime), 0, 8); fs.Write(BitConverter.GetBytes(header.TypeOfNumbers), 0, 2); fs.Write(header.X, 0, header.X.Length); fs.Write(header.ImageHeader, 0, header.ImageHeader.Length); int count = dataList.Count; int barLen = count + 1; for (int n = 0; n < dataList.Count; n++) { ushort[,] data = dataList[n]; int row = data.GetLength(0); int col = data.GetLength(1); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { fs.Write(BitConverter.GetBytes(data[i, j]), 0, 2); } } } fs.Flush(); fs.Dispose(); }