Esempio n. 1
0
        public void Load(Stream aStream)
        {
            var _decoder = new GifBitmapDecoder(aStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

            aStream.Position = 0;
            var _formatIdData = new byte[FormatId.Length];

            aStream.Read(_formatIdData, 0, _formatIdData.Length);
            var _br = new BinaryReader(aStream);

            this.FScreenWidth  = _br.ReadUInt16();
            this.FScreenHeight = _br.ReadUInt16();
            int _flags = _br.ReadByte();

            this.FBackgroundColorIndex = _br.ReadByte();
            aStream.ReadByte();                                                                         // skip pixel shape

            if ((_flags & 0x80) != 0)
            {
                int _bitsPerPixel  = (_flags & 0x07) + 1;
                int _paletteLength = (int)Math.Pow(2, _bitsPerPixel);
                var _colors        = new List <Color>(_paletteLength);

                for (int i = 0; i < _paletteLength; i++)
                {
                    var _c = new Color();
                    _c.R = _br.ReadByte();
                    _c.G = _br.ReadByte();
                    _c.B = _br.ReadByte();
                    _colors.Add(_c);
                }

                this.FGlobalPalette = new BitmapPalette(_colors);
            }

            GifExtension _extension = null;

            while ((_extension = GifExtension.Load(aStream)) != null &&
                   _extension.ExtensionType != ExtensionType.ImageBehaviorExtension)
            {
                this.Extensions.Add(_extension);
            }

            for (int i = 0; i < _decoder.Frames.Count; i++)
            {
                var _currentFrame = new GifBitmapFrame(_decoder.Frames[i]);
                _currentFrame.BehaviorExtention = _extension;
                _extension = _currentFrame.Load(aStream);
                this.Frames.Add(_currentFrame);
            }
        }
Esempio n. 2
0
 public void AddFrame(GifBitmapFrame aFrame)
 {
     this.Frames.Add(aFrame);
 }