本文整理汇总了C#中BinaryReader.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadUInt16方法的具体用法?C# BinaryReader.ReadUInt16怎么用?C# BinaryReader.ReadUInt16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadUInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadWavStreamReadHeaders
public static CWavStreamReadHeaders ReadWavStreamReadHeaders(BinaryReader r)
{
CWavStreamReadHeaders info = new CWavStreamReadHeaders();
info.bIsValid = false;
string riff = new string(r.ReadChars(4));
if (!riff.Equals("RIFF"))
throw new WavCutException("No 'RIFF' Tag, probably not a valid wav file.");
info.nCompleteLength = r.ReadUInt32(); // (length of file in bytes) - 8
string wave = new string(r.ReadChars(4));
if (!wave.Equals("WAVE"))
throw new WavCutException("No 'WAVE' tag, probably not a valid wav file.");
string format = new string(r.ReadChars(4)); // assume that fmt tag is first
if (!format.Equals("fmt "))
throw new WavCutException("No 'fmt ' tag");
uint size = r.ReadUInt32(); // size of fmt header
if (size != 16)
throw new WavCutException("Size of fmt header != 16");
info.nAudioFormat = r.ReadUInt16(); // audio format. 1 refers to uncompressed PCM
// read the format header
info.nChannels = r.ReadUInt16();
info.nSampleRate = r.ReadUInt32();
info.byteRate = r.ReadUInt32();
info.blockAlign = r.ReadUInt16();
info.nBitsPerSample = r.ReadUInt16();
info.bIsValid = true;
return info;
}
示例2: FromIco
public static GroupIconResource FromIco(string FileName)
{
using(FileStream Stream = new FileStream(FileName, FileMode.Open, FileAccess.Read))
{
BinaryReader Reader = new BinaryReader(Stream);
Reader.ReadUInt16(); // Reserved
Reader.ReadUInt16(); // Type
ushort Count = Reader.ReadUInt16();
IconResource[] Icons = new IconResource[Count];
uint[] Offsets = new uint[Count];
for(int Idx = 0; Idx < Count; Idx++)
{
Icons[Idx] = ReadIconHeader(Reader);
Offsets[Idx] = Reader.ReadUInt32();
}
for(int Idx = 0; Idx < Icons.Length; Idx++)
{
Stream.Seek(Offsets[Idx], SeekOrigin.Begin);
Stream.Read(Icons[Idx].Data, 0, Icons[Idx].Data.Length);
}
return new GroupIconResource(Icons);
}
}
示例3: Load
public static GameObject Load(string ModelName)
{
if (ModelsInRAM.ContainsKey(ModelName))
return Object.Instantiate(ModelsInRAM[ModelName]);
if (!File.Exists(Configuration.GameResources + "\\" + ModelName + ".4ds"))
throw new FileNotFoundException("Модель не найдена. Проверьте правильность пути. ");
BinReader = new BinaryReader(File.OpenRead(Configuration.GameResources + "\\" + ModelName + ".4ds"));
if (new string(BinReader.ReadChars(4)) != "4DS\0")
throw new FileLoadException("Неверная сигнатура файла.");
if (BinReader.ReadUInt16() != (ushort)FileVersion.VERSION_MAFIA)
throw new FileLoadException("Данная версия модели не поддерживается.");
ulong TimeStamp = BinReader.ReadUInt64();
Model = new GameObject(Path.GetFileName(ModelName));
ReadMaterials(BinReader.ReadUInt16());
ReadNodes(BinReader.ReadUInt16());
BinReader.BaseStream.Dispose();
ModelsInRAM.Add(ModelName, Model);
return Model;
}
示例4: FromByteArray
public static GroupIconResource FromByteArray(byte[] GroupData, ModuleResourceLibary Module)
{
if (GroupData != null)
{
using (MemoryStream Input = new MemoryStream(GroupData))
{
BinaryReader Reader = new BinaryReader(Input);
Reader.ReadUInt16(); // Reserved
Reader.ReadUInt16(); // Type
ushort Count = Reader.ReadUInt16();
IconResource[] Icons = new IconResource[Count];
for (int Idx = 0; Idx < Count; Idx++)
{
Icons[Idx] = ReadIconHeader(Reader);
int IconId = Reader.ReadUInt16();
Icons[Idx].Data = Module.ReadResource(IconId, ResourceType.Icon);
}
return new GroupIconResource(Icons);
}
}
else
{
return null;
}
}
示例5: LoadFromFile
public static AudioData LoadFromFile(string filename)
{
AudioData audioData = null;
using (BinaryReader reader = new BinaryReader(File.OpenRead(filename)))
{
Debug.Log("Reading wav: " + filename);
reader.BaseStream.Seek(22, SeekOrigin.Begin);
ushort channels = reader.ReadUInt16();
//Debug.Log("Channels: " + channels);
uint sampleRate = reader.ReadUInt32();
//Debug.Log("Sample rate: " + sampleRate);
reader.BaseStream.Seek(34, SeekOrigin.Begin);
ushort bitsPerSample = reader.ReadUInt16();
//Debug.Log("Bits per sample: " + bitsPerSample);
reader.BaseStream.Seek(40, SeekOrigin.Begin);
uint numberOfBytes = reader.ReadUInt32();
//Debug.Log("Number of bytes: " + numberOfBytes);
uint numberOfSamples = numberOfBytes * 8 / bitsPerSample;
//Debug.Log("Number of samples: " + numberOfSamples);
float maxAmplitude = 0.0f;
float[] data = new float[numberOfSamples * channels];
//short[] shortData = new short[numberOfSamples * channels];
byte[] buffer = new byte[numberOfBytes];
if (bitsPerSample / 8 == 2)
{
reader.BaseStream.Seek(44, SeekOrigin.Begin);
buffer = reader.ReadBytes((int)numberOfBytes);
int bufferStep = 0;
for (int i = 0; i < numberOfSamples && bufferStep < buffer.Length; i++)
{
float sample = (float)BitConverter.ToInt16(buffer, bufferStep) / Int16.MaxValue;
float abs = Mathf.Abs(sample);
if (abs > maxAmplitude)
maxAmplitude = abs;
data[i] = sample;
bufferStep += 2;
}
}
else
Debug.LogWarning(filename + "is not a 16-bit wav.");
audioData = new AudioData(data, (int)channels, (int)sampleRate, maxAmplitude, (int)numberOfSamples / (int)channels);
//Debug.Log(filename + " has been loaded!");
}
return audioData;
}
示例6: Load
public void Load(BinaryReader br, FileStream fs)
{
Offset = br.ReadInt32();
Offset += 16;
FrameCount = br.ReadInt32();
MipWidth = br.ReadInt32();
MipHeight = br.ReadInt32();
StartX = br.ReadInt32();
StartY = br.ReadInt32();
TileCount = br.ReadUInt16();
TotalCount = br.ReadUInt16();
CellWidth = br.ReadUInt16();
CellHeight = br.ReadUInt16();
Frames = new EanFrame[TotalCount];
long curPos = fs.Position;
fs.Seek((long)Offset, SeekOrigin.Begin);
for (int i = 0; i < TotalCount; i++)
{
Frames[i].X = br.ReadUInt16();
Frames[i].Y = br.ReadUInt16();
Frames[i].Width = br.ReadUInt16();
Frames[i].Height = br.ReadUInt16();
}
fs.Seek((long)curPos, SeekOrigin.Begin);
}
示例7: GetFiles
public static ZipDirHeader[] GetFiles(BinaryReader br, Func<ZipDirHeader, bool> f)
{
var list = new List<ZipDirHeader>();
var fs = br.BaseStream;
if (fs.Length < 22)
throw new Exception("ファイルが小さ過ぎます。");
fs.Position = fs.Length - 22;
if (br.ReadInt32() != 0x06054b50)
throw new Exception("ヘッダが見付かりません。");
fs.Position += 6;
int count = br.ReadUInt16();
var dir_len = br.ReadUInt32();
var dir_start = br.ReadUInt32();
fs.Position = dir_start;
for (int i = 0; i < count; i++)
{
if (br.ReadInt32() != 0x02014b50)
throw new Exception("ファイルが壊れています。");
var zipdh = new ZipDirHeader(br);
if (f(zipdh)) list.Add(zipdh);
}
return list.ToArray();
}
示例8: Read
public void Read(BinaryReader br)
{
uint magic = br.ReadUInt32(); // +00
if (magic != Util.FOURCC('P', 'S', 'Q', '\0')) {
throw new Exception("invalid data (PSQ)");
}
dataSize = br.ReadUInt32();
nodeNum = br.ReadUInt16();
poseNum = br.ReadUInt16();
vecNum = br.ReadUInt16();
br.ReadUInt16(); // reserved
nodeOffs = br.ReadUInt32();
sizeOffs = br.ReadUInt32();
vecOffs = br.ReadUInt32();
nbits = br.ReadUInt32();
}
示例9: TryReadBlock
//shouldn't ever read the byte at position endExtraField
//assumes we are positioned at the beginning of an extra field subfield
public static bool TryReadBlock(BinaryReader reader, long endExtraField, out ZipGenericExtraField field)
{
field = new ZipGenericExtraField();
//not enough bytes to read tag + size
if (endExtraField - reader.BaseStream.Position < 4)
return false;
field._tag = reader.ReadUInt16();
field._size = reader.ReadUInt16();
//not enough bytes to read the data
if (endExtraField - reader.BaseStream.Position < field._size)
return false;
field._data = reader.ReadBytes(field._size);
return true;
}
示例10: WaveAudio
/// <summary>
/// Initializes this WaveAudio object with Wave audio file.
/// </summary>
/// <param name="filepath">Path of Wave Audio file.</param>
public WaveAudio(FileStream filepath)
{
this.fs = filepath;
this.br = new BinaryReader(fs);
this.riffID = br.ReadBytes(4);
this.size = br.ReadUInt32();
this.wavID = br.ReadBytes(4);
this.fmtID = br.ReadBytes(4);
this.fmtSize = br.ReadUInt32();
this.format = br.ReadUInt16();
this.channels = br.ReadUInt16();
this.sampleRate = br.ReadUInt32();
this.bytePerSec = br.ReadUInt32();
this.blockSize = br.ReadUInt16();
this.bit = br.ReadUInt16();
this.dataID = br.ReadBytes(4);
this.dataSize = br.ReadUInt32();
this.leftStream = new List<short>();
this.rightStream = new List<short>();
for (int i = 0; i < this.dataSize / this.blockSize; i++)
{
leftStream.Add((short)br.ReadUInt16());
rightStream.Add((short)br.ReadUInt16());
}
br.Close();
fs.Close();
}
示例11: ZipHeader
public ZipHeader(BinaryReader br)
{
Version = br.ReadUInt16();
Flags = br.ReadUInt16();
Compression = br.ReadUInt16();
DosTime = br.ReadUInt16();
DosDate = br.ReadUInt16();
Crc32 = br.ReadUInt32();
CompressedSize = br.ReadUInt32();
UncompressedSize = br.ReadUInt32();
FilenameLength = br.ReadUInt16();
ExtraFieldLength = br.ReadUInt16();
}
示例12: ReadTooSmallUInt16Test
public void ReadTooSmallUInt16Test()
{
System.IO.Stream stream = new SerializedStreamBuilder()
.Int64(long.MinValue)
.ToStream();
BinaryReader reader = new BinaryReader(stream, DeserializationHelper.CannedVersion);
TestHelper.ExpectException<TeslaDeserializationException>(
() =>
{
reader.ReadUInt16(string.Empty);
},
"Bad format UInt16 value. The value was read is outside the range of the UInt16.");
}
示例13: beReadUInt16
/// <summary>
/// Reads next 2 bytes as a big-endian UInt16.
/// </summary>
/// <param name="reader">Source reader.</param>
/// <returns>Big-endian UInt16.</returns>
public UInt16 beReadUInt16(BinaryReader reader)
{
return endianSwapUInt16(reader.ReadUInt16());
}
示例14: Parse
public static Tr2Level Parse(byte[] unzippeddata)
{
m_Level = new Tr2Level();
MemoryStream ms = new MemoryStream(unzippeddata);
BinaryReader br = new BinaryReader(ms);
if(System.BitConverter.IsLittleEndian)
{
//readm_LevelVersion
m_Level.Version =br.ReadUInt32();
//print("m_Level.Version " + m_Level.Version );
m_Level.EngineVersion = getTREngineVersionFromVersion(m_Level.Version);
//print("m_Level.EngineVersion " +m_Level.EngineVersion );
if (m_Level.EngineVersion != TR2VersionType.TombRaider_2)
{
return null;
}
m_Level.Palette8 = new Tr2Colour[256];
m_Level.Palette16 = new uint[256];
for(int colorIdx = 0 ; colorIdx < 256; colorIdx++)
{
m_Level.Palette8 [colorIdx].Red = br.ReadByte();
m_Level.Palette8 [colorIdx].Green = br.ReadByte();
m_Level.Palette8 [colorIdx].Blue = br.ReadByte();
}
for(int colorIdx = 0 ; colorIdx < 256; colorIdx++)
{
m_Level.Palette16[colorIdx] = br.ReadUInt32();
}
//read NumTexTiles
m_Level.NumTextiles = br.ReadUInt32();//System.BitConverter.ToUInt32(m_TrLevelData.bytes, sizeof(uint));
//print("m_Level.NumTextiles " + m_Level.NumTextiles );
//Tr2Textile8
m_Level.Textile8 = new Tr2Textile8[m_Level.NumTextiles];
for(int texTilecount = 0 ; texTilecount < m_Level.NumTextiles; texTilecount++)
{
m_Level.Textile8[texTilecount].Tile = br.ReadBytes(256 * 256);
}
//Tr2Textile16
m_Level.Textile16 = new Tr2Textile16[m_Level.NumTextiles];
for(int texTilecount = 0 ; texTilecount < m_Level.NumTextiles; texTilecount++)
{
m_Level.Textile16[texTilecount].Tile = new ushort[256 * 256];
for(uint shortcnt = 0; shortcnt < (256 * 256); shortcnt++)
{
m_Level.Textile16[texTilecount].Tile[shortcnt] = br.ReadUInt16();
}
}
m_Level.m_TexWidth = m_Level.m_MaxWidth;
m_Level.m_TexHeight = (int)m_Level.NumTextiles * m_Level.m_TexWidth;
m_Level.m_MaxTiles = (int)m_Level.NumTextiles;
//padTiles = 16 - m_MaxTiles;
m_Level.UnknownT = br.ReadUInt32(); //unused
m_Level.NumRooms = br.ReadUInt16();
//print("m_Level.NumRooms:"+m_Level.NumRooms);
//extract room details
m_Level.Rooms = new Tr2Room[m_Level.NumRooms];
for (int i = 0; i < m_Level.NumRooms; ++i)
{
//print("process room:"+i);
//print("-------------:");
//print("-------------:");
//get room global data of length
//get room info
//m_Level.Rooms[i].info = new Tr2RoomInfo();
byte[] tmpArr = br.ReadBytes(Tr2RoomInfoSize);
m_Level.Rooms[i].info =(Tr2RoomInfo) Cast2Struct(tmpArr,typeof(Tr2RoomInfo));
//print("m_Level.Rooms["+i+"].info length" + sizeData);
//print("m_Level.Rooms["+i+"].info x z: " + m_Level.Rooms[i].info.x + " " + m_Level.Rooms[i].info.z);
m_Level.Rooms[i].NumDataWords = br.ReadUInt32();
int sizeRoomData = sizeof(ushort) * ((int)m_Level.Rooms[i].NumDataWords);
m_Level.Rooms[i].Data = br.ReadBytes(sizeRoomData);
//print("m_Level.Rooms["+i+"].Data" +System.Buffer.ByteLength(m_Level.Rooms[i].Data));
byte[] dataArr = m_Level.Rooms[i].Data; //variable length data for this room
//create a stream reader
MemoryStream roomDataStream = new MemoryStream(dataArr);
BinaryReader roomReader = new BinaryReader(roomDataStream);
//process ushort NumVertices;
m_Level.Rooms[i].RoomData.NumVertices = roomReader.ReadInt16();
if(m_Level.Rooms[i].RoomData.NumVertices > 0)
{
//print("m_Level.Rooms["+i+"].RoomData.NumVertices" +m_Level.Rooms[i].RoomData.NumVertices);
m_Level.Rooms[i].RoomData.Vertices = new Tr2VertexRoom[m_Level.Rooms[i].RoomData.NumVertices];
//.........这里部分代码省略.........
示例15: GetPAX
/// <summary>
/// Return bitmap of the PAX file
/// <param name="si">MemoryStream of the PAX file/param>
/// </summary>
public static PicPAX GetPAX(MemoryStream si)
{
si.Position = 0;
BinaryReader br = new BinaryReader(si);
if (si.ReadByte() != 0x50) throw new NotSupportedException("!PAX");
if (si.ReadByte() != 0x41) throw new NotSupportedException("!PAX");
if (si.ReadByte() != 0x58) throw new NotSupportedException("!PAX");
if (si.ReadByte() != 0x5F) throw new NotSupportedException("!PAX");
si.Position = 0xC;
int v0c = br.ReadInt32(); // off-to-tbl82
si.Position = v0c;
int test82 = br.ReadInt32();
if (test82 != 0x82) throw new NotSupportedException("!82");
si.Position = v0c + 0xC;
int cx = br.ReadInt32();
PicPAX pp = new PicPAX();
for (int x = 0; x < cx; x++)
{
si.Position = v0c + 16 + 32*x;
int off96 = (v0c + br.ReadInt32());
si.Position = off96;
int test96 = br.ReadInt32();
if (test96 != 0x96) throw new NotSupportedException("!96");
int cnt1 = br.ReadInt32();
List<int> aloff1 = new List<int>(); // dmac tag off?
for (int t = 0; t < cnt1; t++) aloff1.Add(off96 + br.ReadInt32());
int cnt2 = br.ReadInt32();
List<int> aloff2 = new List<int>(); // tex off?
for (int t = 0; t < cnt2; t++) aloff2.Add(off96 + br.ReadInt32());
int cnt3 = br.ReadInt32();
List<int> aloff3 = new List<int>(); // ?
for (int t = 0; t < cnt3; t++) aloff3.Add(off96 + br.ReadInt32());
int cnt4 = br.ReadInt32();
List<int> aloff4 = new List<int>(); // ?
for (int t = 0; t < cnt4; t++) aloff4.Add(off96 + br.ReadInt32());
int cnt5 = br.ReadInt32();
List<int> aloff5 = new List<int>(); // ?
for (int t = 0; t < cnt5; t++) aloff5.Add(off96 + br.ReadInt32());
R or = new R();
pp.alr.Add(or);
for (int t = 0; t < aloff2.Count; t++)
{
int offt2 = aloff2[t];
si.Position = offt2;
br.ReadInt32(); // @0
br.ReadInt16(); // @4
int fmt = br.ReadInt16(); // @6
br.ReadInt32(); // @8
int tcx = br.ReadInt16(); // @12
int tcy = br.ReadInt16(); // @14
if (fmt == 0x13)
{
si.Position = offt2 + 32;
byte[] pic = br.ReadBytes(tcx*tcy);
byte[] pal = br.ReadBytes(1024);
or.pics.Add(BUt.Make8(pic, pal, tcx, tcy, t + 1));
}
}
for (int t = 0; t < aloff3.Count; t++)
{
int offt3 = aloff3[t];
si.Position = offt3 + 0x14;
St3 o3 = new St3();
or.als3.Add(o3);
o3.cnt1 = br.ReadInt16(); // @0x14
o3.cnt2 = br.ReadInt16(); // @0x16
Debug.Assert(o3.cnt1 == o3.cnt2);
for (int s = 0; s < o3.cnt1; s++)
{
si.Position = offt3 + 0x20 + 8*s;
int off3r = br.ReadUInt16();
St3r o3r = new St3r();
o3.al3r.Add(o3r);
//.........这里部分代码省略.........