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


C# Stream.ReadBytes方法代码示例

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


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

示例1: TmpTDReader

		public TmpTDReader(Stream s)
		{
			var width = s.ReadUInt16();
			var height = s.ReadUInt16();
			var size = new Size(width, height);

			s.Position += 8;
			var imgStart = s.ReadUInt32();
			s.Position += 8;
			var indexEnd = s.ReadInt32();
			var indexStart = s.ReadInt32();

			s.Position = indexStart;
			var count = indexEnd - indexStart;
			var tiles = new TmpTile[count];
			Frames = tiles.AsReadOnly();
			var tilesIndex = 0;
			foreach (var b in s.ReadBytes(count))
			{
				if (b != 255)
				{
					s.Position = imgStart + b * width * height;
					tiles[tilesIndex++] = new TmpTile(s.ReadBytes(width * height), size);
				}
				else
					tiles[tilesIndex++] = new TmpTile(null, size);
			}
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:28,代码来源:TmpTDReader.cs

示例2: ParseFrames

		TmpRAFrame[] ParseFrames(Stream s)
		{
			var start = s.Position;
			var width = s.ReadUInt16();
			var height = s.ReadUInt16();
			var size = new Size(width, height);

			s.Position += 12;
			var imgStart = s.ReadUInt32();
			s.Position += 8;
			var indexEnd = s.ReadInt32();
			s.Position += 4;
			var indexStart = s.ReadInt32();

			s.Position = indexStart;
			var count = indexEnd - indexStart;
			var tiles = new TmpRAFrame[count];

			var tilesIndex = 0;
			foreach (var b in s.ReadBytes(count))
			{
				if (b != 255)
				{
					s.Position = imgStart + b * width * height;
					tiles[tilesIndex++] = new TmpRAFrame(s.ReadBytes(width * height), size);
				}
				else
					tiles[tilesIndex++] = new TmpRAFrame(null, size);
			}

			s.Position = start;
			return tiles;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:33,代码来源:TmpRALoader.cs

示例3: TmpRAReader

        public TmpRAReader(Stream s)
        {
            var width = s.ReadUInt16();
            var height = s.ReadUInt16();
            var size = new Size(width, height);

            s.Position += 12;
            var imgStart = s.ReadUInt32();
            s.Position += 8;
            var indexEnd = s.ReadInt32();
            s.Position += 4;
            var indexStart = s.ReadInt32();

            s.Position = indexStart;
            foreach (byte b in s.ReadBytes(indexEnd - indexStart))
            {
                if (b != 255)
                {
                    s.Position = imgStart + b * width * height;
                    tiles.Add(new TmpTile(s.ReadBytes(width * height), size));
                }
                else
                    tiles.Add(new TmpTile(null, size));
            }
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:25,代码来源:TmpRAReader.cs

示例4: Terrain

        public Terrain(Stream s)
        {
            // Try loading as a cnc .tem
            Width = s.ReadUInt16();
            Height = s.ReadUInt16();

            /*NumTiles = */s.ReadUInt16();
            /*Zero1 = */s.ReadUInt16();
            /*uint Size = */s.ReadUInt32();
            var imgStart = s.ReadUInt32();
            /*Zero2 = */s.ReadUInt32();

            int indexEnd, indexStart;

            // ID1 = FFFFh for cnc
            if (s.ReadUInt16() == 65535)
            {
                /*ID2 = */s.ReadUInt16();
                indexEnd = s.ReadInt32();
                indexStart = s.ReadInt32();
            }
            else
            {
                // Load as a ra .tem
                s.Position = 0;
                Width = s.ReadUInt16();
                Height = s.ReadUInt16();

                /*NumTiles = */s.ReadUInt16();
                s.ReadUInt16();
                /*XDim = */s.ReadUInt16();
                /*YDim = */s.ReadUInt16();
                /*uint FileSize = */s.ReadUInt32();
                imgStart = s.ReadUInt32();
                s.ReadUInt32();
                s.ReadUInt32();
                indexEnd = s.ReadInt32();
                s.ReadUInt32();
                indexStart = s.ReadInt32();
            }

            s.Position = indexStart;

            foreach (byte b in s.ReadBytes(indexEnd - indexStart))
            {
                if (b != 255)
                {
                    s.Position = imgStart + b * Width * Height;
                    TileBitmapBytes.Add(s.ReadBytes(Width * Height));
                }
                else
                    TileBitmapBytes.Add(null);
            }
        }
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:54,代码来源:Terrain.cs

示例5: ShpTSFrame

			public ShpTSFrame(Stream s, Size frameSize)
			{
				var x = s.ReadUInt16();
				var y = s.ReadUInt16();
				var width = s.ReadUInt16();
				var height = s.ReadUInt16();

				// Pad the dimensions to an even number to avoid issues with half-integer offsets
				var dataWidth = width;
				var dataHeight = height;
				if (dataWidth % 2 == 1)
					dataWidth += 1;

				if (dataHeight % 2 == 1)
					dataHeight += 1;

				Offset = new int2(x + (dataWidth - frameSize.Width) / 2, y + (dataHeight - frameSize.Height) / 2);
				Size = new Size(dataWidth, dataHeight);
				FrameSize = frameSize;

				Format = s.ReadUInt8();
				s.Position += 11;
				FileOffset = s.ReadUInt32();

				if (FileOffset == 0)
					return;

				// Parse the frame data as we go (but remember to jump back to the header before returning!)
				var start = s.Position;
				s.Position = FileOffset;

				Data = new byte[dataWidth * dataHeight];

				if (Format == 3)
				{
					// Format 3 provides RLE-zero compressed scanlines
					for (var j = 0; j < height; j++)
					{
						var length = s.ReadUInt16() - 2;
						Format2.DecodeInto(s.ReadBytes(length), Data, dataWidth * j);
					}
				}
				else
				{
					// Format 2 provides uncompressed length-prefixed scanlines
					// Formats 1 and 0 provide an uncompressed full-width row
					var length = Format == 2 ? s.ReadUInt16() - 2 : width;
					for (var j = 0; j < height; j++)
						s.ReadBytes(Data, dataWidth * j, length);
				}

				s.Position = start;
			}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:53,代码来源:ShpTSLoader.cs

示例6: ShpTSReader

		public ShpTSReader(Stream stream)
		{
			stream.ReadUInt16();
			var width = stream.ReadUInt16();
			var height = stream.ReadUInt16();
			var size = new Size(width, height);
			var frameCount = stream.ReadUInt16();

			var frames = new FrameHeader[frameCount];
			Frames = frames.AsReadOnly();
			for (var i = 0; i < frames.Length; i++)
				frames[i] = new FrameHeader(stream, size);

			for (var i = 0; i < frameCount; i++)
			{
				var f = frames[i];
				if (f.FileOffset == 0)
					continue;

				stream.Position = f.FileOffset;

				var frameSize = f.Size.Width * f.Size.Height;

				// Uncompressed
				if (f.Format == 1 || f.Format == 0)
					f.Data = stream.ReadBytes(frameSize);

				// Uncompressed scanlines
				else if (f.Format == 2)
				{
					f.Data = new byte[frameSize];
					for (var j = 0; j < f.Size.Height; j++)
					{
						var length = stream.ReadUInt16() - 2;
						var offset = f.Size.Width * j;
						stream.ReadBytes(f.Data, offset, length);
					}
				}

				// RLE-zero compressed scanlines
				else if (f.Format == 3)
				{
					f.Data = new byte[frameSize];
					for (var j = 0; j < f.Size.Height; j++)
					{
						var length = stream.ReadUInt16() - 2;
						var offset = f.Size.Width * j;
						Format2.DecodeInto(stream.ReadBytes(length), f.Data, offset);
					}
				}
			}
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:52,代码来源:ShpTSReader.cs

示例7: R8Image

			public R8Image(Stream s)
			{
				// Scan forward until we find some data
				var type = s.ReadUInt8();
				while (type == 0)
					type = s.ReadUInt8();

				var width = s.ReadInt32();
				var height = s.ReadInt32();
				var x = s.ReadInt32();
				var y = s.ReadInt32();

				Size = new Size(width, height);
				Offset = new int2(width / 2 - x, height / 2 - y);

				/*var imageOffset = */
				s.ReadInt32();
				var paletteOffset = s.ReadInt32();
				var bpp = s.ReadUInt8();
				if (bpp != 8)
					throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));

				var frameHeight = s.ReadUInt8();
				var frameWidth = s.ReadUInt8();
				FrameSize = new Size(frameWidth, frameHeight);

				// Skip alignment byte
				s.ReadUInt8();

				Data = s.ReadBytes(width * height);

				// Ignore palette
				if (type == 1 && paletteOffset != 0)
					s.Seek(520, SeekOrigin.Current);
			}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:35,代码来源:R8Reader.cs

示例8: Read

        /// <summary>
        /// 値をバイト配列として読み取ります。
        /// </summary>
        /// <param name="src">値を読み取るストリーム。</param>
        /// <returns>値となるバイト配列。</returns>
        public byte[] Read( Stream src )
        {
            var position = src.Position;
            src.Seek( this.Position, SeekOrigin.Begin );

            var value = src.ReadBytes( this.Length );
            src.Seek( position, SeekOrigin.Begin );

            return value;
        }
开发者ID:akabekobeko,项目名称:Owl,代码行数:15,代码来源:ObjectTagValueReader.cs

示例9: AuthenticateAsServer

        /// <summary>
        /// Requests that the provided stream be authenticated 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="additionalChallenge">Additional data to include in the challenge. If using SSL certificates, 
        /// adding the thumbprint to the challenge will allow detecting man in the middle attacks.</param>
        /// <returns></returns>
        public ScramServerSession AuthenticateAsServer(Stream stream, byte[] additionalChallenge = null)
        {
            if (additionalChallenge == null)
                additionalChallenge = new byte[] { };

            byte[] usernameBytes = stream.ReadBytes();
            byte[] clientNonce = stream.ReadBytes();

            ScramUserCredential user;
            if (!Users.TryLookup(usernameBytes, out user))
                return null;

            byte[] serverNonce = m_nonce.Next();
            stream.WriteByte((byte)user.HashMethod);
            stream.WriteWithLength(serverNonce);
            stream.WriteWithLength(user.Salt);
            stream.Write(user.Iterations);
            stream.Flush();

            byte[] authMessage = Scram.ComputeAuthMessage(serverNonce, clientNonce, user.Salt, usernameBytes, user.Iterations, additionalChallenge);
            byte[] clientSignature = user.ComputeClientSignature(authMessage);
            byte[] serverSignature = user.ComputeServerSignature(authMessage);
            byte[] clientProof = stream.ReadBytes();

            byte[] clientKeyVerify = Scram.XOR(clientProof, clientSignature);
            byte[] storedKeyVerify = user.ComputeStoredKey(clientKeyVerify);

            if (storedKeyVerify.SecureEquals(user.StoredKey))
            {
                //Client holds the password
                //Send ServerSignature
                stream.WriteWithLength(serverSignature);
                stream.Flush();
                return new ScramServerSession(user.UserName);
            }
            return null;
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:44,代码来源:ScramServer.cs

示例10: Read

        public static Blck Read(Stream stream)
        {
            var result = new Blck();
            var b = (byte)stream.ReadByte();
            result.unknown = (b & 0x80) == 0x80;
            if (!result.unknown) throw new UnknownNodeFlagException();

            result.nameLength = (short)(b & 0x7f);
            result.name = stream.ReadUtf8String(result.nameLength);

            result.length = stream.ReadInt32();
            using (var memStream = new MemoryStream(stream.ReadBytes(result.length)))
                result.children = Aval.Read(memStream).ToList();

            return result;
        }
开发者ID:13xforever,项目名称:Witcher-2-Save-Editor,代码行数:16,代码来源:Blck.cs

示例11: AuthenticateAsServer

        /// <summary>
        /// Requests that the provided stream be authenticated 
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="additionalChallenge">Additional data to include in the challenge. If using SSL certificates, 
        /// adding the thumbprint to the challenge will allow detecting man in the middle attacks.</param>
        /// <returns></returns>
        public SrpServerSession AuthenticateAsServer(Stream stream, byte[] additionalChallenge = null)
        {
            if (additionalChallenge == null)
                additionalChallenge = new byte[] { };

            // Header
            //  C => S
            //  int16   usernameLength (max 1024 characters)
            //  byte[]  usernameBytes

            int len = stream.ReadInt16();
            if (len < 0 || len > 1024)
                return null;

            var usernameBytes = stream.ReadBytes(len);
            var username = UTF8.GetString(usernameBytes);
            var user = Users.Lookup(username);
            var session = new SrpServerSession(user);
            if (session.TryAuthenticate(stream, additionalChallenge))
            {
                return session;
            }
            return null;
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:31,代码来源:SrpServer.cs

示例12: VxlReader

        public VxlReader(Stream s)
        {
            if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
                throw new InvalidDataException("Invalid vxl header");

            s.ReadUInt32();
            LimbCount = s.ReadUInt32();
            s.ReadUInt32();
            BodySize = s.ReadUInt32();
            s.Seek(770, SeekOrigin.Current);

            // Read Limb headers
            Limbs = new VxlLimb[LimbCount];
            for (var i = 0; i < LimbCount; i++)
            {
                Limbs[i] = new VxlLimb();
                Limbs[i].Name = s.ReadASCII(16);
                s.Seek(12, SeekOrigin.Current);
            }

            // Skip to the Limb footers
            s.Seek(802 + 28*LimbCount + BodySize, SeekOrigin.Begin);

            var LimbDataOffset = new uint[LimbCount];
            for (var i = 0; i < LimbCount; i++)
            {
                LimbDataOffset[i] = s.ReadUInt32();
                s.Seek(8, SeekOrigin.Current);
                Limbs[i].Scale = s.ReadFloat();
                s.Seek(48, SeekOrigin.Current);

                Limbs[i].Bounds = new float[6];
                for (var j = 0; j < 6; j++)
                    Limbs[i].Bounds[j] = s.ReadFloat();
                Limbs[i].Size = s.ReadBytes(3);
                Limbs[i].Type = (NormalType)s.ReadByte();
            }

            for (var i = 0; i < LimbCount; i++)
            {
                s.Seek(802 + 28*LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
                ReadVoxelData(s, Limbs[i]);
            }
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:44,代码来源:VxlReader.cs

示例13: String

 public String(SectionHeader header, Stream stream)
     : base(header, stream)
 {
     Value = Encoding.UTF8.GetString(stream.ReadBytes((int) header.Size)).TrimNullChars();
 }
开发者ID:katalist5296,项目名称:SanAndreasUnity,代码行数:5,代码来源:String.cs

示例14: Load

 internal void Load(Stream s)
 {
     Name = Encoding.ASCII.GetString(s.ReadBytes(8)).TrimEnd('\0');
     VirtualSize = s.ReadUIntLE();
     SectionRVA = s.ReadUIntLE();
     SizeOfRawData = s.ReadUIntLE();
     PointerToRawData = s.ReadUIntLE();
     PointerToRelocations = s.ReadUIntLE();
     PointerToLineNumbers = s.ReadUIntLE();
     NumberOfRelocations = s.ReadUShortLE();
     NumberOfLineNumbers = s.ReadUShortLE();
     SectionFlags = (SectionFlags)s.ReadUIntLE();
 }
开发者ID:scottwis,项目名称:Disil,代码行数:13,代码来源:SectionHeader.cs

示例15: ReadImageFrame

		private static ImageFrame ReadImageFrame(Stream stream, byte[] globalColorTable, GraphicControlExtension graphicControlExtension)
		{
			var imageDescriptor = ImageDescriptor.Read(stream);

			var imageFrame = new ImageFrame
				{
					ImageDescriptor = imageDescriptor,
					LocalColorTable = globalColorTable,
					GraphicControlExtension = graphicControlExtension
				};

			if (imageDescriptor.LocalColorTableFlag)
			{
				imageFrame.LocalColorTable = stream.ReadBytes(imageDescriptor.LocalColorTableSize * 3);
			}

			imageFrame.ColorDepth = stream.ReadByte();

			var lzwDecoder = new LzwDecoder(stream);
			var imageData = lzwDecoder.DecodeImageData(imageDescriptor.ImageWidth, imageDescriptor.ImageHeight, imageFrame.ColorDepth);

			ApplicationData.Read(stream);

			imageFrame.Bitmap = CreateBitmap(
				imageData,
				imageFrame.GetPalette(),
				imageDescriptor.InterlaceFlag,
				imageDescriptor.ImageWidth,
				imageDescriptor.ImageHeight);

			return imageFrame;
		}
开发者ID:krabishe,项目名称:GIF89a.Transformation,代码行数:32,代码来源:GifDecoder.cs


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