本文整理汇总了C#中System.IO.BinaryReader.ReadInt16方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadInt16方法的具体用法?C# System.IO.BinaryReader.ReadInt16怎么用?C# System.IO.BinaryReader.ReadInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.ReadInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public void Parse(Header header, byte[] data)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
{
using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
{
_authCode = br.ReadInt32();
_accountId = br.ReadUInt32();
_userLevel = br.ReadUInt32();
_lastLoginIP = br.ReadUInt32();
_lastLoginTime = br.ReadBytes(26);
_sex = br.ReadByte();
_serverList = new Dictionary<string, Server>();
for (int i = (int)ms.Position; i < header.Size; i += 32)
{
Server s = new Server();
s.IP = string.Format("{0}.{1}.{2}.{3}", br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte());
s.Port = br.ReadInt16();
s.Name = br.ReadBytes(22).NullByteTerminatedString();
s.Type = br.ReadInt16();
s.UserCount = br.ReadInt16();
_serverList.Add(s.Name, s);
}
}
}
}
示例2: IsCorrectFormat
public override bool IsCorrectFormat(System.IO.FileStream fs)
{
System.IO.BinaryReader _brdrReader = new System.IO.BinaryReader(fs);
// Make sure file size > 4100 (data begins after a 4100-byte header).
if (fs.Length <= 4100)
{
return false;
}
// Datatype field in header ONLY can be 0~3
// We can finde the datatype at offset 108 according to the file spec.
fs.Seek(108, System.IO.SeekOrigin.Begin);
DataType _dtDataType = (DataType)_brdrReader.ReadInt16();
if (_dtDataType < DataType.SPE_DATA_FLOAT || _dtDataType > DataType.SPE_DATA_UINT)
{
return false;
}
return true;
}
示例3: RGSSTable
public RGSSTable(byte[] raw)
{
System.IO.MemoryStream s = new System.IO.MemoryStream(raw);
System.IO.BinaryReader r = new System.IO.BinaryReader(s);
this.dimensions = (byte)r.ReadInt32();
int x = r.ReadInt32();
int y = r.ReadInt32();
int z = r.ReadInt32();
long check = r.ReadInt32();
this.value = new short[x, y, z];
for (int j = 0; j < z; j++)
{
for (int k = 0; k < y; k++)
{
for (int l = 0; l < x; l++)
{
this[l, k, j] = r.ReadInt16();
}
}
}
}
示例4: WaveFile
public WaveFile(short bitDepth, short channels, int sampleRate, byte[] data)
{
this.bitDepth = bitDepth;
this.channels = channels;
this.sampleRate = sampleRate;
path = null;
name = "[Untitled Recording]";
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
int numSamples = data.Length / (channels * (bitDepth / 8));
samples = new double[channels][];
for (int c = 0; c < channels; c++) {
samples[c] = new double[numSamples];
}
if (bitDepth == 16) {
for (int i = 0; i < numSamples; i++) {
for (int c = 0; c < channels; c++) {
//assuming signed
//normalized to -1.0..+1.0
samples[c][i] = (double)br.ReadInt16() / 32768.0;
}
}
} else if (bitDepth == 8) {
for (int i = 0; i < numSamples; i++) {
for (int c = 0; c < channels; c++) {
//assuming unsigned
//normalized to -1.0..+1.0
samples[c][i] = (double)br.ReadByte() / 128.0 - 1.0;
}
}
} else {
throw new FormatException("Bit depth must be one of 8 or 16 bits.");
}
}
示例5: readFile
public void readFile()
{
System.IO.BinaryReader sr;
try { //TODO: test, rather than try/fail?
sr = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open));
} catch (System.IO.IOException) {
throw;
}
//====================
//RIFF chunk id
char[] ckID = sr.ReadChars(4);
String a = new string(ckID);
if (a.CompareTo("RIFF") != 0) {
throw new FormatException("RIFF chunkID missing. Found " + ckID[0] + ckID[1] + ckID[2] + ckID[3] + ".");
}
UInt32 RIFFSize = sr.ReadUInt32();
//====================
//WAVE chunk id
ckID = sr.ReadChars(4);
a = new string(ckID);
if (a.CompareTo("WAVE") != 0) {
throw new FormatException("WAVE chunkID missing. Found " + ckID[0] + ckID[1] + ckID[2] + ckID[3] + ".");
}
//====================
//fmt_ chunk id
ckID = sr.ReadChars(4);
a = new string(ckID);
UInt32 chunkSize = sr.ReadUInt32();
while (a.CompareTo("fmt ") != 0) {
sr.ReadBytes((int)chunkSize);
ckID = sr.ReadChars(4);
a = new string(ckID);
chunkSize = sr.ReadUInt32();
}
Int16 wFormatTag = sr.ReadInt16();
Int16 nChannels = sr.ReadInt16();
Int32 nSamplesPerSec = sr.ReadInt32();
Int32 nAvgBytesPerSec = sr.ReadInt32();
Int16 nBlockAlign = sr.ReadInt16();
Int16 wBitsPerSample = sr.ReadInt16();
chunkSize -= 16;
//there may be more bytes in fmt_ so skip those.
sr.ReadBytes((int)chunkSize);
if (wFormatTag != 0x0001) {
throw new FormatException("Invalid wave format. Only PCM wave files supported.");
}
//====================
//data chunk id
ckID = sr.ReadChars(4);
a = new string(ckID);
chunkSize = sr.ReadUInt32();
while (a.CompareTo("data") != 0) {
sr.ReadBytes((int)chunkSize);
ckID = sr.ReadChars(4);
a = new string(ckID);
chunkSize = sr.ReadUInt32();
}
channels = (short)nChannels;
bitDepth = (short)wBitsPerSample;
sampleRate = nSamplesPerSec;
long numSamples = chunkSize / (bitDepth / 8) / channels;
samples = new double[channels][];
for (int c = 0; c < channels; c++) {
samples[c] = new double[numSamples];
}
//======================
// read samples
if (bitDepth == 16) {
for (int i = 0; i < numSamples; i++) {
for (int c = 0; c < channels; c++) {
//assuming signed
//normalized to -1.0..+1.0
samples[c][i] = (double)sr.ReadInt16() / 32768.0;
}
}
} else if (bitDepth == 8) {
for (int i = 0; i < numSamples; i++) {
for (int c = 0; c < channels; c++) {
//assuming unsigned
//normalized to -1.0..+1.0
samples[c][i] = (double)sr.ReadByte() / 128.0 - 1.0;
}
}
} else {
throw new FormatException("Bit depth must be one of 8 or 16 bits.");
}
sr.Close();
}
示例6: Ole10Native
public Ole10Native(System.IO.Stream inputStream)
{
System.IO.BinaryReader reader = new System.IO.BinaryReader(inputStream);
totalSize = reader.ReadInt32();
if (totalSize < 4)
{
throw new Exception(
String.Format("Invalid total data size: {0}.", totalSize));
}
flags1 = reader.ReadInt16();
label = ReadString(reader);
fileName = ReadString(reader);
flags2 = reader.ReadInt16();
byte unknown1Len = reader.ReadByte();
unknown1 = reader.ReadBytes(unknown1Len);
unknown2 = reader.ReadBytes(3);
command = ReadString(reader);
nativeDataSize = reader.ReadInt32();
if (nativeDataSize > totalSize || nativeDataSize < 0)
{
throw new Exception(
String.Format("Invalid native data size: {0}.", nativeDataSize));
}
nativeData = reader.ReadBytes(nativeDataSize);
unknown3 = unknown1.Length > 0 ? reader.ReadInt16() : (short)0;
}
示例7: Populate
public void Populate(int iOffset, int iIndexedReflexiveOffset)
{
this.isNulledOutReflexive = false;
System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
int mapMetaOffset = meta.offset;
if (this._EntIndex.reflexiveTagType + this._EntIndex.reflexiveTagName != string.Empty)
{
int tagNum = map.Functions.ForMeta.FindByNameAndTagType(this._EntIndex.reflexiveTagType, this._EntIndex.reflexiveTagName);
if (tagNum != -1)
{
Meta meta2 = new Meta(map);
map.OpenMap(MapTypes.Internal);
meta2.ReadMetaFromMap(tagNum, true);
map.CloseMap();
mapMetaOffset = meta2.offset;
this._EntIndex.reflexiveLayer = "root";
}
}
if (this._EntIndex.reflexiveLayer.ToLower() == "root")
this._IndexedReflexiveOffset = mapMetaOffset + this._EntIndex.ReflexiveOffset;
else if (this._EntIndex.reflexiveLayer.ToLower() == "oneup")
this._IndexedReflexiveOffset = iIndexedReflexiveOffset + this._EntIndex.ReflexiveOffset;
/*
bool openedMap = false;
if (map.isOpen == false)
{
map.OpenMap(MapTypes.Internal);
openedMap = true;
}
map.BA.Position = iOffset + this.chunkOffset;
*/
BR.BaseStream.Position = iOffset + this.chunkOffset;
this.offsetInMap = meta.offset + iOffset + this.chunkOffset;
switch (_ValueType)
{
case IFPIO.ObjectEnum.Short:
{
this.Value = (int)BR.ReadInt16();
break;
}
case IFPIO.ObjectEnum.Int:
{
this.Value = BR.ReadInt32();
break;
}
case IFPIO.ObjectEnum.UShort:
{
this.Value = (int)BR.ReadUInt16();
break;
}
case IFPIO.ObjectEnum.UInt:
{
this.Value = (int)BR.ReadUInt32();
break;
}
case IFPIO.ObjectEnum.Byte:
{
this.Value = (int)BR.ReadByte();
break;
}
}
UpdateSelectionList(false);
/*
if (openedMap == true)
map.CloseMap();
*/
}
示例8: LoadHeightmapFromImageFile
public static HeightData LoadHeightmapFromImageFile(string path){
Config config = Main.Get().GetConfig();
HeightData heights;
string ext = path.Substring(path.LastIndexOf('.'), path.Length - path.LastIndexOf('.')).ToLower();
if (ext == ".shd")
{
// byte-by-byte binary reading
System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open, System.IO.FileAccess.Read));
// read first eight bytes with map dimensions
int width = reader.ReadInt32();
int height = reader.ReadInt32();
heights = new HeightData((UInt16) width,(UInt16) height);
// read the double bytes containing the height data
for (int i = 0; i < width * height; i++)
{
heights[i] = reader.ReadInt16();
}
reader.Close();
reader.Dispose();
}
else
{
// read the bitmap file
System.Drawing.Bitmap bitmap;
try
{
bitmap = new System.Drawing.Bitmap(path);
}
catch(ArgumentException){
return null;
}
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bitmap.PixelFormat);
heights = new HeightData((UInt16) bitmap.Width, (UInt16)bitmap.Height);
// prepare memory space for the color data
byte[] bytes = new byte[data.Stride * bitmap.Height];
int pixelSize = data.Stride / data.Width;
// get a pointer to the to first line (=first pixel)
IntPtr ptr = data.Scan0;
// create a byte copy of the heightmap data
System.Runtime.InteropServices.Marshal.Copy(ptr, bytes, 0, data.Stride * bitmap.Height);
// create the color data
for (int i = 0; i < bytes.Length; i += pixelSize)
{
heights[i / pixelSize] = (short)((short)bytes[i] * 128);
}
bitmap.UnlockBits(data);
bitmap.Dispose();
}
HeightData heights2 = Main.GetResizedHeightData(heights, Math.Min(heights.Width, (int)config.mapDetailLevel), Math.Min(heights.Height, (int)config.mapDetailLevel));
return heights2;
}
示例9: HidDataReceived
/// <summary>
/// Handles HidDataReceived events and processes incoming raw data from the
/// Device. Fills m_Translation and m_Rotation objects with the filtered and
/// scaled raw data. At the end fire SensorInput to notify clients.
/// </summary>
/// <param name="sender"></param>
/// <param name="p_HidDataReceivedEventArgs"></param>
private void HidDataReceived(object sender, HidDataReceivedEventArgs p_HidDataReceivedEventArgs)
{
short x = 0;
short y = 0;
short z = 0;
///////////////////////////////
// set Length of translation //
// movement to 0 zeroes also //
// x, y and z components //
///////////////////////////////
m_Translation.Length = 0;
///////////////////////////////
// set Angle of rotation //
// movement to 0 zeroes also //
// x, y and z components //
///////////////////////////////
m_Rotation.Angle = 0;
///////////////////////////////
// handling the translation //
///////////////////////////////
if (p_HidDataReceivedEventArgs[0] == c_Translation)
{
try
{
byte[] buffer = {
p_HidDataReceivedEventArgs[1],
p_HidDataReceivedEventArgs[2],
p_HidDataReceivedEventArgs[3],
p_HidDataReceivedEventArgs[4],
p_HidDataReceivedEventArgs[5],
p_HidDataReceivedEventArgs[6],
};
System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
x = reader.ReadInt16();
y = reader.ReadInt16();
z = reader.ReadInt16();
/*
Console.Out.WriteLine("transX: {0}", x);
Console.Out.WriteLine("transY: {0}", y);
Console.Out.WriteLine("transZ: {0}", z);
*/
////////////////////////////////////////
// Filtering and scaling is done here //
// X value of Aerion Input data must //
// be multiplied with -1 //
////////////////////////////////////////
m_Translation.X = m_TranslationFunction(System.Convert.ToDouble(x), c_MaxValueTranslation) * XScaleFactor;
m_Translation.Y = m_TranslationFunction(System.Convert.ToDouble(y), c_MaxValueTranslation) * YScaleFactor;
m_Translation.Z = m_TranslationFunction(System.Convert.ToDouble(z), c_MaxValueTranslation) * ZScaleFactor;
}
catch (Exception e)
{
Console.Out.WriteLine("Exception: {0}, {1}, {2}", e.GetType(), e.Message, e.StackTrace);
}
}
///////////////////////////
// handling the rotation //
///////////////////////////
else if (p_HidDataReceivedEventArgs[0] == c_Rotation)
{
try
{
byte[] buffer = {
p_HidDataReceivedEventArgs[1],
p_HidDataReceivedEventArgs[2],
p_HidDataReceivedEventArgs[3],
p_HidDataReceivedEventArgs[4],
p_HidDataReceivedEventArgs[5],
p_HidDataReceivedEventArgs[6],
};
System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, 0, buffer.Length);
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
x = reader.ReadInt16();
y = reader.ReadInt16();
z = reader.ReadInt16();
/*
Console.Out.WriteLine("rotX: {0}", x);
Console.Out.WriteLine("rotY: {0}", y);
Console.Out.WriteLine("rotZ: {0}", z);
*/
//.........这里部分代码省略.........
示例10: ToArrays
/// <summary>
/// Imports a Galactic SPC file into a x and an y array. The file must not be a multi spectrum file (an exception is thrown in this case).
/// </summary>
/// <param name="xvalues">The x values of the spectrum.</param>
/// <param name="yvalues">The y values of the spectrum.</param>
/// <param name="filename">The filename where to import from.</param>
/// <returns>Null if successful, otherwise an error description.</returns>
public static string ToArrays(string filename, out double [] xvalues, out double [] yvalues)
{
System.IO.Stream stream=null;
SPCHDR hdr = new SPCHDR();
SUBHDR subhdr = new SUBHDR();
try
{
stream = new System.IO.FileStream(filename,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
System.IO.BinaryReader binreader = new System.IO.BinaryReader(stream);
hdr.ftflgs = binreader.ReadByte(); // ftflgs : not-evenly spaced data
hdr.fversn = binreader.ReadByte(); // fversn : new version
hdr.fexper = binreader.ReadByte(); // fexper : general experimental technique
hdr.fexp = binreader.ReadByte(); // fexp : fractional scaling exponent (0x80 for floating point)
hdr.fnpts = binreader.ReadInt32(); // fnpts : number of points
hdr.ffirst = binreader.ReadDouble(); // ffirst : first x-value
hdr.flast = binreader.ReadDouble(); // flast : last x-value
hdr.fnsub = binreader.ReadInt32(); // fnsub : 1 (one) subfile only
binreader.ReadByte(); // Type of X axis units (see definitions below)
binreader.ReadByte(); // Type of Y axis units (see definitions below)
binreader.ReadByte(); // Type of Z axis units (see definitions below)
binreader.ReadByte(); // Posting disposition (see GRAMSDDE.H)
binreader.Read(new byte[0x1E0],0,0x1E0); // rest of SPC header
// ---------------------------------------------------------------------
// following the x-values array
// ---------------------------------------------------------------------
if(hdr.fversn!=0x4B)
{
if(hdr.fversn==0x4D)
throw new System.FormatException(string.Format("This SPC file has the old format version of {0}, the only version supported here is the new version {1}",hdr.fversn,0x4B));
else
throw new System.FormatException(string.Format("This SPC file has a version of {0}, the only version recognized here is {1}",hdr.fversn,0x4B));
}
if(0!=(hdr.ftflgs & 0x80))
{
xvalues = new double[hdr.fnpts];
for(int i=0;i<hdr.fnpts;i++)
xvalues[i] = binreader.ReadSingle();
}
else if(0==hdr.ftflgs) // evenly spaced data
{
xvalues = new double[hdr.fnpts];
for(int i=0;i<hdr.fnpts;i++)
xvalues[i] = hdr.ffirst + i*(hdr.flast-hdr.ffirst)/(hdr.fnpts-1);
}
else
{
throw new System.FormatException("The SPC file must not be a multifile; only single file format is accepted!");
}
// ---------------------------------------------------------------------
// following the y SUBHEADER
// ---------------------------------------------------------------------
subhdr.subflgs = binreader.ReadByte(); // subflgs : always 0
subhdr.subexp = binreader.ReadByte(); // subexp : y-values scaling exponent (set to 0x80 means floating point representation)
subhdr.subindx = binreader.ReadInt16(); // subindx : Integer index number of trace subfile (0=first)
subhdr.subtime = binreader.ReadSingle(); // subtime; Floating time for trace (Z axis corrdinate)
subhdr.subnext = binreader.ReadSingle(); // subnext; Floating time for next trace (May be same as beg)
subhdr.subnois = binreader.ReadSingle(); // subnois; Floating peak pick noise level if high byte nonzero
subhdr.subnpts = binreader.ReadInt32(); // subnpts; Integer number of subfile points for TXYXYS type
subhdr.subscan = binreader.ReadInt32(); // subscan; Integer number of co-added scans or 0 (for collect)
subhdr.subwlevel = binreader.ReadSingle(); // subwlevel; Floating W axis value (if fwplanes non-zero)
subhdr.subresv = binreader.ReadInt32(); // subresv[4]; Reserved area (must be set to zero)
// ---------------------------------------------------------------------
// following the y-values array
// ---------------------------------------------------------------------
yvalues = new double[hdr.fnpts];
if(hdr.fexp==0x80) //floating point format
{
for(int i=0;i<hdr.fnpts;i++)
yvalues[i] = binreader.ReadSingle();
}
else // fixed exponent format
{
//.........这里部分代码省略.........
示例11: LoadLogs
/// <summary>Loads the black-box logs from the previous simulation run</summary>
internal static void LoadLogs()
{
string BlackBoxFile = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "logs.bin");
try
{
using (System.IO.FileStream Stream = new System.IO.FileStream(BlackBoxFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
using (System.IO.BinaryReader Reader = new System.IO.BinaryReader(Stream, System.Text.Encoding.UTF8))
{
byte[] Identifier = new byte[] { 111, 112, 101, 110, 66, 86, 69, 95, 76, 79, 71, 83 };
const short Version = 1;
byte[] Data = Reader.ReadBytes(Identifier.Length);
for (int i = 0; i < Identifier.Length; i++)
{
if (Identifier[i] != Data[i]) throw new System.IO.InvalidDataException();
}
short Number = Reader.ReadInt16();
if (Version != Number) throw new System.IO.InvalidDataException();
Game.LogRouteName = Reader.ReadString();
Game.LogTrainName = Reader.ReadString();
Game.LogDateTime = DateTime.FromBinary(Reader.ReadInt64());
Interface.CurrentOptions.GameMode = (Interface.GameMode)Reader.ReadInt16();
Game.BlackBoxEntryCount = Reader.ReadInt32();
Game.BlackBoxEntries = new Game.BlackBoxEntry[Game.BlackBoxEntryCount];
for (int i = 0; i < Game.BlackBoxEntryCount; i++)
{
Game.BlackBoxEntries[i].Time = Reader.ReadDouble();
Game.BlackBoxEntries[i].Position = Reader.ReadDouble();
Game.BlackBoxEntries[i].Speed = Reader.ReadSingle();
Game.BlackBoxEntries[i].Acceleration = Reader.ReadSingle();
Game.BlackBoxEntries[i].ReverserDriver = Reader.ReadInt16();
Game.BlackBoxEntries[i].ReverserSafety = Reader.ReadInt16();
Game.BlackBoxEntries[i].PowerDriver = (Game.BlackBoxPower)Reader.ReadInt16();
Game.BlackBoxEntries[i].PowerSafety = (Game.BlackBoxPower)Reader.ReadInt16();
Game.BlackBoxEntries[i].BrakeDriver = (Game.BlackBoxBrake)Reader.ReadInt16();
Game.BlackBoxEntries[i].BrakeSafety = (Game.BlackBoxBrake)Reader.ReadInt16();
Game.BlackBoxEntries[i].EventToken = (Game.BlackBoxEventToken)Reader.ReadInt16();
}
Game.ScoreLogCount = Reader.ReadInt32();
Game.ScoreLogs = new Game.ScoreLog[Game.ScoreLogCount];
Game.CurrentScore.Value = 0;
for (int i = 0; i < Game.ScoreLogCount; i++)
{
Game.ScoreLogs[i].Time = Reader.ReadDouble();
Game.ScoreLogs[i].Position = Reader.ReadDouble();
Game.ScoreLogs[i].Value = Reader.ReadInt32();
Game.ScoreLogs[i].TextToken = (Game.ScoreTextToken)Reader.ReadInt16();
Game.CurrentScore.Value += Game.ScoreLogs[i].Value;
}
Game.CurrentScore.Maximum = Reader.ReadInt32();
Identifier = new byte[] { 95, 102, 105, 108, 101, 69, 78, 68 };
Data = Reader.ReadBytes(Identifier.Length);
for (int i = 0; i < Identifier.Length; i++)
{
if (Identifier[i] != Data[i]) throw new System.IO.InvalidDataException();
}
Reader.Close();
} Stream.Close();
}
}
catch
{
Game.LogRouteName = "";
Game.LogTrainName = "";
Game.LogDateTime = DateTime.Now;
Game.BlackBoxEntries = new Game.BlackBoxEntry[256];
Game.BlackBoxEntryCount = 0;
Game.ScoreLogs = new Game.ScoreLog[64];
Game.ScoreLogCount = 0;
}
}
示例12: Populate
public void Populate(int iOffset, bool useMemoryStream)
{
this.isNulledOutReflexive = false;
System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
//set offsets
BR.BaseStream.Position = iOffset + this.chunkOffset;
this.offsetInMap = iOffset + this.chunkOffset;
// If we need to read / save tag info directly to file...
if (!useMemoryStream)
{
map.OpenMap(MapTypes.Internal);
BR = map.BR;
BR.BaseStream.Position = this.offsetInMap;
}
else
this.offsetInMap += meta.offset;
this.sidIndexer = BR.ReadInt16();
byte tempnull = BR.ReadByte();
byte sidLength = BR.ReadByte();
// ...and then close the file once we are done!
if (!useMemoryStream)
map.CloseMap();
try
{
string s = map.Strings.Name[this.sidIndexer];
if (map.Strings.Length[this.sidIndexer] == sidLength)
{
if (this.comboBox1.DataSource == null)
{
this.comboBox1.Items.Clear();
this.comboBox1.Items.Add(s);
this.comboBox1.SelectedIndex = 0;
}
else
this.comboBox1.SelectedIndex = this.sidIndexer; //.Text = s;
}
else
this.comboBox1.Text = "";
}
catch
{
this.comboBox1.Text = "error reading sid";
}
/*
if (AddEvents == true)
{
this.comboBox1.TextChanged += new System.EventHandler(this.comboBox1_TextChanged);
AddEvents = false;
}
*/
}
示例13: Populate
public void Populate(int iOffset, bool useMemoryStream)
{
this.isNulledOutReflexive = false;
System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
//set offsets
BR.BaseStream.Position = iOffset + this.chunkOffset;
this.offsetInMap = iOffset + this.chunkOffset;
// If we need to read / save tag info directly to file...
if (!useMemoryStream)
{
map.OpenMap(MapTypes.Internal);
BR = map.BR;
BR.BaseStream.Position = this.offsetInMap;
}
else
this.offsetInMap += meta.offset;
switch (this.enumType)
{
case 8:
{
this.value = (int)BR.ReadByte();
break;
}
case 16:
{
this.value = (int)BR.ReadInt16();
break;
}
case 32:
{
this.value = BR.ReadInt32();
break;
}
}
// ...and then close the file once we are done!
if (!useMemoryStream)
map.CloseMap();
UpdateComboBox();
}
示例14: LoadData
public override void LoadData(System.IO.FileStream __fsFileStream)
{
System.IO.BinaryReader _brdrReader = new System.IO.BinaryReader(__fsFileStream);
// only read necessary params from file header
__fsFileStream.Seek(42, System.IO.SeekOrigin.Begin);
int _iXDimension = (int)_brdrReader.ReadInt16();
__fsFileStream.Seek(108, System.IO.SeekOrigin.Begin);
DataType _dtDataType = (DataType)_brdrReader.ReadInt16();
__fsFileStream.Seek(656, System.IO.SeekOrigin.Begin);
int _iYDimension = (int)_brdrReader.ReadInt16();
__fsFileStream.Seek(1446, System.IO.SeekOrigin.Begin);
UInt32 numframes = (UInt32)_brdrReader.ReadInt32();
// Start reading the XCalibStruct.
SpeCalib XCalib = new SpeCalib(0, 0);
__fsFileStream.Seek(3000, System.IO.SeekOrigin.Begin);
XCalib.Offset = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3008, System.IO.SeekOrigin.Begin);
XCalib.Factor = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3016, System.IO.SeekOrigin.Begin);
XCalib.current_unit = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3098, System.IO.SeekOrigin.Begin);
XCalib.CalibValid = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3101, System.IO.SeekOrigin.Begin);
XCalib.PolynomOrder = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3263, System.IO.SeekOrigin.Begin);
XCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();
__fsFileStream.Seek(3311, System.IO.SeekOrigin.Begin);
XCalib.LaserPosition = (double)_brdrReader.ReadDouble();
// Start reading the YCalibStruct.
SpeCalib YCalib = new SpeCalib(0, 0);
__fsFileStream.Seek(3489, System.IO.SeekOrigin.Begin); // move ptr to x_calib start
YCalib.Offset = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3497, System.IO.SeekOrigin.Begin);
YCalib.Factor = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3505, System.IO.SeekOrigin.Begin);
YCalib.current_unit = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3587, System.IO.SeekOrigin.Begin);
YCalib.CalibValid = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3590, System.IO.SeekOrigin.Begin);
YCalib.PolynomOrder = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3752, System.IO.SeekOrigin.Begin);
YCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();
__fsFileStream.Seek(3800, System.IO.SeekOrigin.Begin);
YCalib.LaserPosition = (double)_brdrReader.ReadDouble();
int _iDimension;
SpeCalib _calCurrCalib;
if (_iYDimension == 1)
{
_iDimension = _iXDimension;
_calCurrCalib = XCalib;
}
else if (_iXDimension == 1)
{
_iDimension = _iYDimension;
_calCurrCalib = YCalib;
}
else
{
throw new UnexpectedFormatException("xylib does not support 2-D images");
}
__fsFileStream.Seek(4100, System.IO.SeekOrigin.Begin); // move ptr to frames-start
for (int frm = 0; frm < (int)numframes; frm++)
{
Block _blkBlock = new Block();
Column _colXCol = this.GetCalibColumn(_calCurrCalib, _iDimension);
_blkBlock.AddColumn(_colXCol, "", true);
ListColumn _colYCol = new ListColumn();
for (int i = 0; i < _iDimension; ++i)
{
double _dYVal = 0;
switch (_dtDataType)
{
case DataType.SPE_DATA_FLOAT:
_dYVal = (double)_brdrReader.ReadSingle();
break;
case DataType.SPE_DATA_LONG:
_dYVal = (double)_brdrReader.ReadInt32();
break;
//.........这里部分代码省略.........
示例15: Populate
public void Populate(int iOffset, bool useMemoryStream)
{
this.isNulledOutReflexive = false;
System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
//set offsets
BR.BaseStream.Position = iOffset + this.chunkOffset;
this.offsetInMap = iOffset + this.chunkOffset;
// If we need to read / save tag info directly to file...
if (!useMemoryStream)
{
map.OpenMap(MapTypes.Internal);
BR = map.BR;
BR.BaseStream.Position = this.offsetInMap;
}
else
this.offsetInMap += meta.offset;
switch (ValueType)
{
case IFPIO.ObjectEnum.Short:
{
this.Value = BR.ReadInt16();
break;
}
case IFPIO.ObjectEnum.Int:
{
this.Value = BR.ReadInt32();
break;
}
case IFPIO.ObjectEnum.UShort:
{
this.Value = BR.ReadUInt16();
break;
}
case IFPIO.ObjectEnum.UInt:
{
this.Value = BR.ReadUInt32();
break;
}
case IFPIO.ObjectEnum.Float:
{
this.Value = BR.ReadSingle();
break;
}
case IFPIO.ObjectEnum.Unknown:
{
this.Value = BR.ReadSingle();
break;
}
case IFPIO.ObjectEnum.Byte:
{
this.Value = BR.ReadByte();
break;
}
}
// ...and then close the file once we are done!
if (!useMemoryStream)
map.CloseMap();
if (this.ValueType != IFPIO.ObjectEnum.Unused)
this.Controls[1].Text = this.Value.ToString();
}