ImageTools.IO.Gif.GifDecoder.Decode C# (CSharp) Méthode

Decode() public méthode

Decodes the image from the specified stream and sets the data to image.
/// is null (Nothing in Visual Basic). /// - or - /// is null (Nothing in Visual Basic). ///
public Decode ( ExtendedImage image, Stream stream ) : void
image ExtendedImage The image, where the data should be set to. /// Cannot be null (Nothing in Visual Basic).
stream Stream The stream, where the image should be /// decoded from. Cannot be null (Nothing in Visual Basic).
Résultat void
        public void Decode(ExtendedImage image, Stream stream)
        {
            _image = image;

            _stream = stream;
            _stream.Seek(6, SeekOrigin.Current);

            ReadLogicalScreenDescriptor();

            if (_logicalScreenDescriptor.GlobalColorTableFlag == true)
            {
                _globalColorTable = new byte[_logicalScreenDescriptor.GlobalColorTableSize * 3];

                // Read the global color table from the stream
                stream.Read(_globalColorTable, 0, _globalColorTable.Length);
            }

            int nextFlag = stream.ReadByte();
            while (nextFlag != 0)
            {
                if (nextFlag == ImageLabel)
                {
                    ReadFrame();
                }
                else if (nextFlag == ExtensionIntroducer)
                {
                    int gcl = stream.ReadByte();
                    switch (gcl)
                    {
                        case GraphicControlLabel:
                            ReadGraphicalControlExtension();
                            break;
                        case CommentLabel:
                            ReadComments();
                            break;
                        case ApplicationExtensionLabel:
                            Skip(12);
                            break;
                        case PlainTextLabel:
                            Skip(13);
                            break;
                    }
                }
                else if (nextFlag == EndIntroducer)
                {
                    break;
                }
                nextFlag = stream.ReadByte();
            }
        }

Usage Example

		private void init(Stream stream, GIFFrameUpdatedCallbackMethod frameUpdatedCallback)
		{
			// set gif frame update callback
			this.FrameUpdatedCallback = frameUpdatedCallback;

			// decode gif image
			var gifDecoder = new GifDecoder();
			var image = new ExtendedImage();
			gifDecoder.Decode(image, stream);

			// add frames and load unity textures
			frames = new List<TextureGIFFrame>();
			var firstFrame = new TextureGIFFrame(createTexture(image.PixelWidth, image.PixelHeight, image.Pixels), TimeSpan.FromSeconds(image.DelayTime / 100d));
			frames.Add(firstFrame);
			var lastFrame = firstFrame;
			foreach (var frame in image.Frames)
			{
				var newFrame = new TextureGIFFrame(createTexture(frame.PixelWidth, frame.PixelHeight, frame.Pixels), TimeSpan.FromSeconds(frame.DelayTime / 100d));
				frames.Add(newFrame);
				if (lastFrame != null) lastFrame.nextFrame = newFrame;
				lastFrame = newFrame;
			}

			// set starting image
			CurrentFrame = frames[0];
			lastFrame.nextFrame = firstFrame;
		}
All Usage Examples Of ImageTools.IO.Gif.GifDecoder::Decode