当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.BinaryReader.ReadChars方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadChars方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadChars方法的具体用法?C# System.IO.BinaryReader.ReadChars怎么用?C# System.IO.BinaryReader.ReadChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了System.IO.BinaryReader.ReadChars方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Populate

        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(map.SelectedMeta.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 += map.SelectedMeta.offset;

            if (this.entUnicode)
            {
                this.value = Encoding.Unicode.GetString(BR.ReadBytes(this.length));
            }
            else
            {
                this.value = new String(BR.ReadChars(this.length));
            }
            this.value = this.value.TrimEnd('\0');
            //this.RemoveNullCharFromValue();
            this.textBox1.Text = this.value;
            this.textBox1.Size = this.textBox1.PreferredSize;
            this.textBox1.Width += 5;

            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:35,代码来源:EntStrings.cs

示例2: Show_Info

        public System.Windows.Forms.Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = new String(br.ReadChars(4));
            br.Close();

            if (ext == "NFTR" || ext == "RTFN")
            {
                return new FontControl(pluginHost, NFTR.Read(file, pluginHost.Get_Language()));
            }

            return new System.Windows.Forms.Control();
        }
开发者ID:MetLob,项目名称:tinke,代码行数:13,代码来源:Main.cs

示例3: Show_Info

        public Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = "";
            try { ext = new String(br.ReadChars(4)); }
            catch { }
            br.Close();

            if (file.name.ToUpper().EndsWith(".TGA"))
                return new TGA(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".JPG"))
                return new JPG(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".PNG"))
                return new PNG(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".WAV") || ext == "RIFF")
                return new WAV(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".BMP"))
                return new BMP(pluginHost, file.path).Show_Info();

            return new Control();
        }
开发者ID:MetLob,项目名称:tinke,代码行数:21,代码来源:Main.cs

示例4: 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();
        }
开发者ID:JoePelz,项目名称:DSPProject,代码行数:97,代码来源:WaveFile.cs

示例5: 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;

            if (doesHaveTagType)
            {
                int nullCheck = BR.ReadInt32();
                if (nullCheck != -1)
                {
                    BR.BaseStream.Position -= 4;
                    char[] temptype = BR.ReadChars(4);
                    Array.Reverse(temptype);
                    this.tagType = new string(temptype);
                }
                else
                    this.tagType = "null";
            }
            else
                this.tagType = "null";

            int tempint = BR.ReadInt32();
            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
            this.tagIndex = map.Functions.ForMeta.FindMetaByID(tempint);
            if (this.tagIndex != -1)
            {
                this.tagType = map.MetaInfo.TagType[this.tagIndex];
                this.tagName = map.FileNames.Name[this.tagIndex];
            }
            else
            {
                this.tagName = "null";
            }
            this.identInt32 = tempint;

            this.UpdateIdentBoxes();
        }
开发者ID:troymac1ure,项目名称:Entity,代码行数:51,代码来源:Ident.cs

示例6: Load

 public static ActionLibrary Load(System.IO.Stream s)
 {
     ActionLibrary lib = new ActionLibrary();
     System.IO.BinaryReader br = new System.IO.BinaryReader(s, Encoding.ASCII);
     lib.GameMakerVersion = br.ReadInt32();
     bool gm5 = lib.GameMakerVersion == 500;
     lib.TabCaption = new string(br.ReadChars(br.ReadInt32()));
     lib.LibraryID = br.ReadInt32();
     lib.Author = new string(br.ReadChars(br.ReadInt32()));
     lib.Version = br.ReadInt32();
     lib.LastChanged = new DateTime(1899, 12, 30).AddDays(br.ReadDouble());
     lib.Info = new string(br.ReadChars(br.ReadInt32()));
     lib.InitializationCode = new string(br.ReadChars(br.ReadInt32()));
     lib.AdvancedModeOnly = br.ReadInt32() == 0 ? false : true;
     lib.ActionNumberIncremental = br.ReadInt32();
     for (int i = br.ReadInt32(); i > 0; i--)
     {
         int ver = br.ReadInt32();
         ActionDefinition a = new ActionDefinition(lib, new string(br.ReadChars(br.ReadInt32())), br.ReadInt32());
         a.GameMakerVersion = ver;
         int size = br.ReadInt32();
         a.OriginalImage = new byte[size];
         br.Read(a.OriginalImage, 0, size);
         System.IO.MemoryStream ms = new System.IO.MemoryStream(a.OriginalImage);
         System.Drawing.Bitmap b = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
         a.Image = new System.Drawing.Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         using (var g = System.Drawing.Graphics.FromImage(a.Image))
         {
             g.DrawImage(b, new System.Drawing.Rectangle(0, 0, b.Width, b.Height));
         }
         if (b.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
             ((System.Drawing.Bitmap)a.Image).MakeTransparent(b.GetPixel(0, b.Height - 1));
         ms.Close();
         b.Dispose();
         a.Hidden = br.ReadInt32() == 0 ? false : true;
         a.Advanced = br.ReadInt32() == 0 ? false : true;
         a.RegisteredOnly = ver == 500 || (br.ReadInt32() == 0) ? false : true;
         a.Description = new string(br.ReadChars(br.ReadInt32()));
         a.ListText = new string(br.ReadChars(br.ReadInt32()));
         a.HintText = new string(br.ReadChars(br.ReadInt32()));
         a.Kind = (ActionKind)br.ReadInt32();
         a.InterfaceKind = (ActionInferfaceKind)br.ReadInt32();
         a.IsQuestion = br.ReadInt32() == 0 ? false : true;
         a.ShowApplyTo = br.ReadInt32() == 0 ? false : true;
         a.ShowRelative = br.ReadInt32() == 0 ? false : true;
         a.ArgumentCount = br.ReadInt32();
         int count = br.ReadInt32();
         if (a.Arguments.Length != count)
             a.Arguments = new ActionArgument[count];
         for (int j = 0; j < count; j++)
         {
             a.Arguments[j] = new ActionArgument();
             a.Arguments[j].Caption = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Type = (ActionArgumentType)br.ReadInt32();
             a.Arguments[j].DefaultValue = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Menu = new string(br.ReadChars(br.ReadInt32()));
         }
         a.ExecutionType = (ActionExecutionType)br.ReadInt32();
         a.FunctionName = new string(br.ReadChars(br.ReadInt32()));
         a.Code = new string(br.ReadChars(br.ReadInt32()));
         lib.Actions.Add(a);
     }
     //Hmm...
     //ActionDefinition d = new ActionDefinition(lib);
     //d.Description = "Font...";
     //d.ArgumentCount = 1;
     //d.Arguments[0] = new ActionArgument();
     //d.Arguments[0].Type = ActionArgumentType.FontString;
     //d.ListText = "@0";
     //lib.Actions.Add(d);
     //d.Arguments[0].DefaultValue = "\"Times New Roman\",10,0,0,0,0,0";
     return lib;
 }
开发者ID:MilesBoulanger,项目名称:game-creator,代码行数:73,代码来源:ActionLibrary.cs

示例7: LoadWave

        /// <summary>Loads a wave/riff audio file from a stream. Resource file can be passed as the stream.</summary>
        private static byte[] LoadWave(System.IO.Stream stream, out int channels, out int bits, out int rate)
        {
            if (stream == null) throw new ArgumentNullException("stream");

            // ReSharper disable UnusedVariable
            using (var reader = new System.IO.BinaryReader(stream))
            {
                //RIFF header
                var signature = new string(reader.ReadChars(4));
                if (signature != "RIFF") throw new NotSupportedException("Specified stream is not a wave file.");

                int riffChunckSize = reader.ReadInt32();

                var format = new string(reader.ReadChars(4));
                if (format != "WAVE") throw new NotSupportedException("Specified stream is not a wave file.");

                //WAVE header
                var formatSignature = new string(reader.ReadChars(4));
                if (formatSignature != "fmt ") throw new NotSupportedException("Specified wave file is not supported.");

                int formatChunkSize = reader.ReadInt32();
                int audioFormat = reader.ReadInt16();
                int numChannels = reader.ReadInt16();
                int sampleRate = reader.ReadInt32();
                int byteRate = reader.ReadInt32();
                int blockAlign = reader.ReadInt16();
                int bitsPerSample = reader.ReadInt16();

                var dataSignature = new string(reader.ReadChars(4));
                //check if the data dignature for this chunk is LIST headers, can happen with .wav files from web, or when converting other formats such as .mp3 to .wav using tools such as audacity
                //if this happens, the extra header info can be cleared using audacity, export to wave and select 'clear' when the extra header info window appears
                //see http://www.lightlink.com/tjweber/StripWav/WAVE.html
                if (dataSignature == "LIST") throw new NotSupportedException("Specified wave file contains LIST headers (author, copyright etc).");
                if (dataSignature != "data") throw new NotSupportedException("Specified wave file is not supported.");

                int dataChunkSize = reader.ReadInt32();

                channels = numChannels;
                bits = bitsPerSample;
                rate = sampleRate;

                return reader.ReadBytes((int)reader.BaseStream.Length);
            }
            // ReSharper restore UnusedVariable
        }
开发者ID:MagistrAVSH,项目名称:voxelgame,代码行数:46,代码来源:Audio.cs


注:本文中的System.IO.BinaryReader.ReadChars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。