Esempio n. 1
0
        private static void GifCoderTest()
        {
            var _gifFileName = "F_LAW.gif";

            var _input = new FileStream(_gifFileName, FileMode.Open);

            var _gifCoder = new GifBitmapCoder();

            _gifCoder.Load(_input);
            _input.Close();

            for (int i = 0; i < _gifCoder.Frames.Count; i++)
            {
                var _output  = String.Format(@"result\{0}{1:d3}.gif", Path.GetFileNameWithoutExtension(_gifFileName), i);
                var _encoder = new GifBitmapEncoder();
                _encoder.Frames.Add(_gifCoder.Frames[i].Frame);

                using (var _fs = new FileStream(_output, FileMode.Create))
                {
                    _encoder.Save(_fs);
                }
            }

            var _output1 = new FileStream("output.gif", FileMode.Create);

            _gifCoder.Save(_output1);
            _output1.Close();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //var _gifFileName = "truck_crush.gif";
            var _gifFileName = "football.gif";

            var _gifCoder = new GifBitmapCoder();
            var _input    = new FileStream(_gifFileName, FileMode.Open);

            _gifCoder.Load(_input);

            _input.Close();

            for (int i = 0; i < _gifCoder.Frames.Count; i++)
            {
                _gifCoder.Frames[i].Delay = 1 + i % 31;
                //_gifCoder.Frames[i].Delay = 11;

                var _encoder = new BmpBitmapEncoder();
                _encoder.Frames.Add(_gifCoder.Frames[i].Frame);

                string _file = String.Format(@"result\output{0}.bmp", i);
                var    _fs   = new FileStream(_file, FileMode.Create);
                _encoder.Save(_fs);
                _fs.Close();
            }

            var _outputFileName = "football_slow_mo.gif";
            //var _outputFileName = "truck_crush.gif";
            var _output = new FileStream(_outputFileName, FileMode.Create);

            _gifCoder.Save(_output);

            _output.Close();
        }
Esempio n. 3
0
        private static void DisposalMethodTest()
        {
            // var _fileName = "SpartanFla.gif";
            var _fileName = "output.gif";

            var _input = new FileStream(_fileName, FileMode.Open);

            var _gifCoder = new GifBitmapCoder();

            _gifCoder.Load(_input);
            _input.Close();

            foreach (var _frame in _gifCoder.Frames)
            {
                // _frame.DisposalMethod = GifFrameDisposalMethod.RestoreToPrevious;
                _frame.DisposalMethod = GifFrameDisposalMethod.NotDispose;
            }

            var _output = new FileStream("output.gif", FileMode.Create);

            _gifCoder.Save(_output);
            _output.Close();
        }
Esempio n. 4
0
        private void Convert(string aFileName)
        {
            if (FOffsetX == null && !String.IsNullOrEmpty(this.OffsetFileName))
            {
                string _data = null;
                using (var _offsetFile = File.OpenText(this.FOffsetFileName))
                {
                    _data = _offsetFile.ReadToEnd();
                }

                string[] _offsets = _data.Split(new char[] { ' ', '/' }, StringSplitOptions.RemoveEmptyEntries);
                if (_offsets.Length % 2 != 0)
                {
                    throw new FileFormatException("Odd numbers in offset file.");
                }

                this.FOffsetX = new short[_offsets.Length / 2];
                this.FOffsetY = new short[_offsets.Length / 2];
                for (int i = 0; i < _offsets.Length; i++)
                {
                    short _offset = 0;
                    if (Int16.TryParse(_offsets[i], out _offset))
                    {
                        if (i % 2 == 0)
                        {
                            this.FOffsetX[i / 2] = _offset;
                        }
                        else
                        {
                            this.FOffsetY[i / 2] = _offset;
                        }
                    }
                    else
                    {
                        throw new FileFormatException("Can't parse number in offset file.");
                    }
                }
            }

            var _input = new FileStream(aFileName, FileMode.Open);

            var _gifDecoder = new GifBitmapCoder();

            _gifDecoder.Load(_input);
            _input.Close();

            foreach (var _frame in _gifDecoder.Frames)
            {
                if (!_frame.UseGlobalPalette)
                {
                    this.ExceptionString =
                        "Внимание! В GIF файле для некоторых кадров используются локальные палитры. Изображение будет искажено.";
                    break;
                }
            }

            var _stci = Converter.ConvertGifToStciIndexed(
                _gifDecoder, this.IsTransparentBackground, this.IsTrimBackground, this.ForeshotingAmount);

            if (this.FOffsetX != null)
            {
                if (this.FOffsetX.Length > 1 && _stci.Images.Length != this.FOffsetX.Length)
                {
                    throw new ArgumentOutOfRangeException("Number frames in STCI is not equal to number of records in offset file");
                }

                for (int i = 0; i < _stci.Images.Length; i++)
                {
                    if (this.FOffsetX.Length == 1)
                    {
                        _stci.Images[i].Header.OffsetX = this.FOffsetX[0];
                        _stci.Images[i].Header.OffsetY = this.FOffsetY[0];
                    }
                    else
                    {
                        _stci.Images[i].Header.OffsetX = this.FOffsetX[i];
                        _stci.Images[i].Header.OffsetY = this.FOffsetY[i];
                    }
                }
            }

            using (var _output = new FileStream(Path.ChangeExtension(aFileName, ".sti"), FileMode.Create))
                _stci.Save(_output);
        }