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


C# Stream.ReadShort方法代码示例

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


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

示例1: Read

		public static PlainTextExtension Read(Stream stream)
		{
			var blockSize = stream.ReadByte();
			if (blockSize != BlockSize)
			{
				throw new GifException("Plain text extension data format error");
			}

			var result = new PlainTextExtension
				{
					TextGridLeftPosition = stream.ReadShort(),
					TextGridTopPosition = stream.ReadShort(),
					TextGridWidth = stream.ReadShort(),
					TextGridHeight = stream.ReadShort(),
					CharacterCellWidth = (byte) stream.ReadByte(),
					CharacterCellHeight = (byte) stream.ReadByte(),
					TextForegroundColorIndex = (byte) stream.ReadByte(),
					TextBackgroundColorIndex = (byte) stream.ReadByte(),
					PlainTextData = new List<string>()
				};

			blockSize = stream.ReadByte();
			while (blockSize > 0)
			{
				var plainTextData = stream.ReadString(blockSize);
				result.PlainTextData.Add(plainTextData);

				blockSize = stream.ReadByte();
			}

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

示例2: Unpack

        /* Unpack a GMP into a Bitmap */
        public override Bitmap Unpack(ref Stream data)
        {
            try
            {
                /* Get and set image variables */
                int width      = data.ReadInt(0xC); // Width
                int height     = data.ReadInt(0x8); // Height
                short bitDepth = data.ReadShort(0x1E); // Bit Depth
                short colors   = data.ReadShort(0x1C); // Pallete Entries

                /* Throw an exception if this is not an 8-bit gmp (for now) */
                if (bitDepth != 8)
                    throw new Exception();

                /* Set up the image */
                Bitmap image = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
                BitmapData imageData = image.LockBits(
                    new Rectangle(0, 0, width, height),
                    ImageLockMode.WriteOnly, image.PixelFormat);

                /* Read the data from the GMP */
                unsafe
                {
                    /* Write the palette */
                    ColorPalette palette = image.Palette;
                    for (int i = 0; i < colors; i++)
                        palette.Entries[i] = Color.FromArgb(data.ReadByte(0x20 + (i * 0x4) + 0x2), data.ReadByte(0x20 + (i * 0x4) + 0x1), data.ReadByte(0x20 + (i * 0x4)));

                    image.Palette = palette;

                    /* Start getting the pixels from the source image */
                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            byte* rowData = (byte*)imageData.Scan0 + (y * imageData.Stride);
                            rowData[x] = data.ReadByte(0x20 + (colors * 0x4) + (width * height) - ((y + 1) * width) + x);
                        }
                    }
                }

                /* Unlock the bits now. */
                image.UnlockBits(imageData);

                return image;
            }
            catch
            {
                return null;
            }
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:52,代码来源:gmp.cs

示例3: Read

		public static LogicalScreenDescriptor Read(Stream stream)
		{
			var result = new LogicalScreenDescriptor
				{
					LogicalScreenWidth = stream.ReadShort(),
					LogicalScreenHeight = stream.ReadShort(),
					PackedFields = (byte) stream.ReadByte()
				};

			result.GlobalColorTableFlag = ((result.PackedFields & 0x80) >> 7) == 1;
			result.ColorResolution = (byte) ((result.PackedFields & 0x60) >> 5);
			result.SortFlag = (byte) (result.PackedFields & 0x10) >> 4;
			result.GlobalColorTableSize = 2 << (result.PackedFields & 0x07);
			result.BackgroundColorIndex = (byte) stream.ReadByte();
			result.PixelAspectRatio = (byte) stream.ReadByte();

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

示例4: Read

		public static ImageDescriptor Read(Stream stream)
		{
			var result = new ImageDescriptor
				{
					ImageLeftPosition = stream.ReadShort(),
					ImageTopPosition = stream.ReadShort(),
					ImageWidth = stream.ReadShort(),
					ImageHeight = stream.ReadShort(),
					PackedFields = (byte) stream.ReadByte()
				};

			result.LocalColorTableFlag = ((result.PackedFields & 0x80) >> 7) == 1;
			result.InterlaceFlag = ((result.PackedFields & 0x40) >> 6) == 1;
			result.SortFlag = ((result.PackedFields & 0x20) >> 5) == 1;
			result.LocalColorTableSize = (2 << (result.PackedFields & 0x07));

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

示例5: Read

		public static GraphicControlExtension Read(Stream stream)
		{
			var blockSize = stream.ReadByte();
			if (blockSize != BlockSize)
			{
				throw new GifException("Graphic control extension data format error");
			}

			var result = new GraphicControlExtension
				{
					PackedFields = (byte) stream.ReadByte()
				};

			result.TransparentColorFlag = (result.PackedFields & 0x01) == 1;
			result.DisposalMethod = (result.PackedFields & 0x1C) >> 2;
			result.DelayTime = stream.ReadShort();
			result.TransparentColorIndex = (byte) stream.ReadByte();
			stream.ReadByte();

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

示例6: ReadFromStream

 public override void ReadFromStream(Stream aStream)
 {
     SlotID = aStream.ReadShort ();
 }
开发者ID:rbrian,项目名称:mccslib,代码行数:4,代码来源:Packets.cs

示例7: ReadMessageIdentifier

 protected void ReadMessageIdentifier(Stream stream) {
     MessageIdentifier = stream.ReadShort();
     length += 2;
 }
开发者ID:fm0597,项目名称:nmqtt,代码行数:4,代码来源:MqttVariableHeader.cs

示例8: ReadKeepAlive

 protected void ReadKeepAlive(Stream stream) {
     KeepAlive = stream.ReadShort();
     length += 2;
 }
开发者ID:fm0597,项目名称:nmqtt,代码行数:4,代码来源:MqttVariableHeader.cs

示例9: DecodeParamI4

        internal int DecodeParamI4(Stream reader)
        {
            switch (this.flags & OpcodeFlags.OperandType) {
            case OpcodeFlags.NoOperand:
                throw new Exception ("no param");
            case OpcodeFlags.OperandSize1:
                return reader.ReadByte ();
            case OpcodeFlags.OperandSize2:
                return reader.ReadShort ();
            case OpcodeFlags.OperandSize4:
                return reader.ReadInt ();
            case OpcodeFlags.OperandSize8:
                throw new Exception ("param of size 8");

            case OpcodeFlags.OperandSwitch:
                throw new Exception ("variable length param");
            default:
                throw new Exception ("invalid opcode type " + this.flags);
            }
        }
开发者ID:kumpera,项目名称:SimpleJIT,代码行数:20,代码来源:Opcode.cs

示例10: CreateExceptionFromError

        private static Exception CreateExceptionFromError(Stream stream)
        {
            ErrorCodes code = (ErrorCodes) stream.ReadInt();
            string msg = stream.ReadString();

            switch (code)
            {
                case ErrorCodes.Unavailable:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int required = stream.ReadInt();
                        int alive = stream.ReadInt();
                        return new UnavailableException(msg, cl, required, alive);
                    }

                case ErrorCodes.WriteTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        string writeType = stream.ReadString();
                        return new WriteTimeOutException(msg, cl, received, blockFor, writeType);
                    }

                case ErrorCodes.ReadTimeout:
                    {
                        ConsistencyLevel cl = (ConsistencyLevel) stream.ReadShort();
                        int received = stream.ReadInt();
                        int blockFor = stream.ReadInt();
                        bool dataPresent = 0 != stream.ReadByte();
                        return new ReadTimeOutException(msg, cl, received, blockFor, dataPresent);
                    }

                case ErrorCodes.Syntax:
                    return new SyntaxException(msg);

                case ErrorCodes.Unauthorized:
                    return new UnauthorizedException(msg);

                case ErrorCodes.Invalid:
                    return new InvalidException(msg);

                case ErrorCodes.AlreadyExists:
                    {
                        string keyspace = stream.ReadString();
                        string table = stream.ReadString();
                        return new AlreadyExistsException(msg, keyspace, table);
                    }

                case ErrorCodes.Unprepared:
                    {
                        byte[] unknownId = stream.ReadShortBytes();
                        return new UnpreparedException(msg, unknownId);
                    }

                default:
                    return new CassandraException(code, msg);
            }
        }
开发者ID:Hamdiakoguz,项目名称:cassandra-sharp,代码行数:59,代码来源:StreamingFrameReader.cs


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