本文整理汇总了C#中System.IO.BinaryReader.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadByte方法的具体用法?C# System.IO.BinaryReader.ReadByte怎么用?C# System.IO.BinaryReader.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckUploadByTwoByte
/// <summary>
/// 根据文件的前2个字节进行判断文件类型 ---说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
/// </summary>
/// <param name="hpf"></param>
/// <param name="code">文件的前2个字节转化出来的小数</param>
/// <returns></returns>
public bool CheckUploadByTwoByte(HttpPostedFile hpf, Int64 code)
{
System.IO.FileStream fs = new System.IO.FileStream(hpf.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch
{
}
r.Close();
fs.Close();
//
//if (fileclass == code.ToString())
//{
// return true;
//}
//else
//{
// return false;
//}
return (fileclass == code.ToString());
}
示例2: 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);
}
}
}
}
示例3: ExtractSPR
static void ExtractSPR(string filename)
{
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.OpenRead("TIBIA.SPR"))) {
ushort count = reader.ReadUInt16();
reader.BaseStream.Seek(6, System.IO.SeekOrigin.Current);
for (int a = 1; a < count; a++) {
Bitmap bmp = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
bmp.Palette = colorPalette;
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, 32, 32), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
byte[] byteArray = new byte[1024];
for (int b = 0; b < 1024; b++) {
byteArray[b] = 0xFF;
}
long size = reader.ReadUInt16();
size += reader.BaseStream.Position - 1;
int i = 0;
while (reader.BaseStream.Position <= size) {
if (reader.BaseStream.Position >= reader.BaseStream.Length) {
break;
}
ushort tPixels = reader.ReadUInt16();
i += tPixels;
if (reader.BaseStream.Position > size) {
break;
}
byte cPixels = reader.ReadByte();
for (int c = 0; c < cPixels; c++) {
byte color = reader.ReadByte();
byteArray[i] = color;
i++;
}
}
System.Runtime.InteropServices.Marshal.Copy(byteArray, 0, bmpData.Scan0, 1024);
bmp.UnlockBits(bmpData);
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
if (!System.IO.Directory.Exists(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\"))) {
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\"));
}
bmp.Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "Sprites\\" + a.ToString() + ".bmp"));
bmp.Dispose();
}
}
}
示例4: Load
public static void Load()
{
IO.Log.Write(" Loading CampaingProgresss...");
levelsCompleted.Clear();
System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream("Saves/progress.lpg",
System.IO.FileMode.Open));
String s = "";
int l = 0;
while (br.PeekChar() > -1)
{
s = br.ReadString();
l = br.ReadInt32();
byte[] d = new byte[l];
for (int j = 0; j < l; j++)
{
d[j] = br.ReadByte();
}
levelsCompleted.Add(s, d);
}
br.Close();
IO.Log.Write(" Loading complete");
}
示例5: 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))
{
_errorCode = br.ReadByte();
_blockDate = br.ReadBytes(20).NullByteTerminatedString();
}
}
}
示例6: ReturnBinaryByteFromFile
public static byte[] ReturnBinaryByteFromFile(string path)
{
var stream = System.IO.File.OpenRead(path);
System.IO.BinaryReader br = new System.IO.BinaryReader(stream);
byte[] binary = new byte[br.BaseStream.Length];
for (int i = 0; i < binary.Length; i++)
{
binary[i] = br.ReadByte();
}
return binary;
}
示例7: ExtractPIC
static void ExtractPIC(string filename)
{
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(System.IO.File.OpenRead(filename))) {
ushort width = (ushort)(reader.ReadUInt16() + 2);
ushort height = (ushort)(reader.ReadUInt16() + 2);
Bitmap bmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
bmp.Palette = colorPalette;
System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
byte[] byteArray = new byte[width * height];
for (int x = 1; x < (height - 1); x++) {
for (int y = 1; y < (width - 1); y++) {
byteArray[(width * x) + y] = reader.ReadByte();
}
}
System.Runtime.InteropServices.Marshal.Copy(byteArray, 0, bmpData.Scan0, width * height);
bmp.UnlockBits(bmpData);
bmp.Save(filename.Substring(0, filename.IndexOf(".")) + ".bmp");
bmp.Dispose();
}
}
示例8: ParseFile
public static System.Windows.Forms.TreeNode ParseFile(string path)
{
// Read archive tree
uint nFiles, baseOffset;
System.Windows.Forms.TreeNode node = new System.Windows.Forms.TreeNode();
System.IO.BinaryReader stream = new System.IO.BinaryReader(System.IO.File.OpenRead(path));
stream.ReadUInt32();
nFiles = stream.ReadUInt32();
baseOffset = stream.ReadUInt32();
for (int i = 0; i < nFiles; i++)
{
char b;
FileEntry f = new FileEntry();
do
{
b = (char)stream.ReadByte();
if (b != 0)
f.name += b;
} while (b != 0);
f.length = stream.ReadUInt32();
stream.ReadUInt32();
f.offset = baseOffset;
baseOffset += f.length;
f.idx = (uint)i;
System.Windows.Forms.TreeNode n = new System.Windows.Forms.TreeNode(f.name);
n.Tag = f;
node.Nodes.Add(n);
}
return node;
}
示例9: 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.");
}
}
示例10: 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();
}
示例11: 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();
}
示例12: IsAllowedImage
/// <summary>
/// 检查是否为允许的图片格式
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private bool IsAllowedImage(string filePath)
{
bool ret = false;
System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch
{
return false;
}
r.Close();
fs.Close();
/*文件扩展名说明
*7173 gif
*255216 jpg
*13780 png
*6677 bmp
*239187 txt,aspx,asp,sql
*208207 xls.doc.ppt
*6063 xml
*6033 htm,html
*4742 js
*8075 xlsx,zip,pptx,mmap,zip
*8297 rar
*01 accdb,mdb
*7790 exe,dll
*5666 psd
*255254 rdp
*10056 bt种子
*64101 bat
*/
// String[] fileType = { "255216", "7173", "6677", "13780", "8297", "5549", "870", "87111", "8075" };
string[] fileType = { "255216", "7173", "6677", "13780" };
for (int i = 0; i < fileType.Length; i++)
{
if (fileclass == fileType[i])
{
ret = true;
break;
}
}
return ret;
}
示例13: simpleButton1_Click
private void simpleButton1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
//Alimenta a variável das datas
dataInicio = dateTimePickerInicio.Value.ToString("dd-MM-yyyy");
dataFinal = dateTimePickerFinal.Value.ToString("dd-MM-yyyy");
SqlConnection conn = new ConnectionFactory().getConnection();
SqlCommand cmd = new SqlCommand(@"select distinct(codpromotor) as codpromotor from movpromotores
where data between @dataini and @datafim", conn);
cmd.Parameters.AddWithValue("@dataini", dateTimePickerInicio.Value);
cmd.Parameters.AddWithValue("@datafim", dateTimePickerFinal.Value);
try
{
cxTotal.Text = getQuantidade().ToString();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ReportDocument rpDocument =
new CarregaRelatorio().carregarRelatorio(montaQuery(reader["codpromotor"].ToString()), "T:\\rel\\relatorioDisparo.rpt");
//Cria um stream do pdf
System.IO.Stream st =
rpDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
//Faz a leitura do stream para byte
System.IO.BinaryReader br = new System.IO.BinaryReader(st);
byte[] pdfByte = new byte[st.Length];
for (int i = 0; i < st.Length; ++i)
{
pdfByte[i] = br.ReadByte();
}
//Fecha o stream e o byte reader
st.Close();
br.Close();
//Grava o email na fila de envio
if (gravaLogEMail(reader["codpromotor"].ToString(), pdfByte))
{
listBox1.Items.Add("Promotor "+ reader["codpromotor"].ToString() + " -> Gerou com sucesso!");
}
else
{
listBox1.Items.Add("Promotor " + reader["codpromotor"].ToString() + " -> Falha ao gerar");
}
listBox1.SelectedIndex = listBox1.Items.Count-1;
quantidade.Text = (listBox1.Items.Count).ToString();
if (listBox1.Items.Count == Convert.ToInt64(cxTotal.Text))
MessageBox.Show("O processo foi finalizado com sucesso!");
rpDocument.Close();
Application.DoEvents();
}
reader.Close();
}catch(Exception exc)
{
MessageBox.Show("Erro ao gerar relatório\n"+ exc);
}
finally
{
conn.Close();
}
}
示例14: GetResponseCallback
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response;
// End the get response operation
response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
System.IO.Stream streamResponse = response.GetResponseStream();
System.IO.BinaryReader inputstream = new System.IO.BinaryReader(streamResponse);
if (inputstream.BaseStream.Length > 0)
{
byte[] responsebytes = new byte[inputstream.BaseStream.Length];
int totalRead = 0;
while (totalRead < inputstream.BaseStream.Length)
{
responsebytes[totalRead++] = inputstream.ReadByte();
}
ArraySegment<byte> raw = new ArraySegment<byte>(responsebytes, 0, totalRead);
PCOSMessageBase msg = PCOSMsgFactory.Parse(raw);
OnPingPongResponse(this, new PingPongEventArgs(msg));
}
streamResponse.Close();
inputstream.Close();
response.Close();
}
catch (WebException e)
{
}
}
示例15: GetFileTrueType
/// <summary>
/// 真正判断文件类型的关键函数(不太准确,比如txt获取到的值都不一样)
/// </summary>
/// <param name="hifile"></param>
/// <returns></returns>
public static string GetFileTrueType(System.Web.HttpPostedFile postedFile)
{
//System.IO.FileStream fs = new System.IO.FileStream(strPhysicsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.Stream fs = postedFile.InputStream;
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch { }
r.Close();
fs.Close();
/*文件扩展名说明
*7173 gif
*255216 jpg
*13780 png
*6677 bmp
*239187 txt,aspx,asp,sql
*208207 xls.doc.ppt
*6063 xml
*6033 htm,html
*4742 js
*8075 xlsx,zip,pptx,mmap,zip
*8297 rar
*01 accdb,mdb
*7790 exe,dll
*5666 psd
*255254 rdp
*10056 bt种子
*64101 bat
*/
if (fileclass == "255216")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
{
return "jpg";
}
else if (fileclass == "7173")
{
return "gif";
}
else if (fileclass == "6677")
{
return "bmp";
}
else if (fileclass == "13780")
{
return "png";
}
else if (fileclass == "7790")
{
return "exe";
}
else if (fileclass == "8297")
{
return "rar/zip";
}
else if (fileclass == "208207")
{
return "doc/xls";
}
else if (fileclass == "8075")
{
return "docx/xlsx";
}
else if (fileclass == "5155")
{
return "txt";
}
else if (fileclass == "6787")
{
return "swf";
}
else
{
return "";
}
}