Dispose() public method

Disposes all resources used by this instance of the TargaImage class.
public Dispose ( ) : void
return void
示例#1
0
        private void threadSpellIcons_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] _files;

            e.Result = DialogResult.Abort;

            try
            {
                _files = Directory.GetFiles(_InputFolder, "spells??.tga");
                string _outPath = _OutputFolder;

                if (!Directory.Exists(_outPath))
                {
                    Directory.CreateDirectory(_outPath);
                }

                _SpellIcons = _files.Length * _SpellIconsPerFile;

                int _count = 0;

                string _spellFileName;

                for (int _spellIconSheet = 0; _spellIconSheet < 100; _spellIconSheet++)
                {
                    if (File.Exists(_spellFileName = _InputFolder + @"\spells" + (_spellIconSheet + 1).ToString("00") + ".tga"))
                    {
                        int _x = _SpellIconStart.X;
                        int _y = _SpellIconStart.Y;
                        int _iconIndex = 0;

                        TargaImage _iconSheet = new TargaImage(_spellFileName);

                        while ((_y + _SpellIconSize.Y) < _iconSheet.Image.Height)
                        {
                            string _outFile = _outPath + @"\" + ((_spellIconSheet * _SpellIconsPerFile) + _iconIndex).ToString() + ".png";

                            Bitmap _icon = new Bitmap(_SpellIconSize.X, _SpellIconSize.Y, _iconSheet.Image.PixelFormat);
                            Graphics _blitter = Graphics.FromImage(_icon);
                            _blitter.DrawImage(_iconSheet.Image, 0, 0, new Rectangle(_x, _y, _SpellIconSize.X, _SpellIconSize.Y), GraphicsUnit.Pixel);
                            _blitter.Dispose();
                            _icon.Save(_outFile);
                            _icon.Dispose();

                            _iconIndex++;
                            _x += _SpellIconSize.X + _SpellIconPadding.X;

                            if ((_x + _SpellIconSize.X) >= _iconSheet.Image.Width)
                            {
                                _x = _SpellIconStart.X;
                                _y += _SpellIconSize.Y + _SpellIconPadding.Y;
                            }

                            _TotalSpellIconCount++;
                            threadSpellIcons.ReportProgress(_count++);

                            if (threadSpellIcons.CancellationPending)
                            {
                                e.Result = DialogResult.Cancel;

                                return;
                            }
                        }

                        _iconSheet.Dispose();
                    }
                }
            }
            catch
            {
                return;
            }

            e.Result = DialogResult.OK;

            return;
        }