コード例 #1
0
ファイル: Form1.cs プロジェクト: yujintong/bni-icon-builder
        private Bitmap _loadBitmapWithDialog()
        {
            Bitmap bitmap;

            var d = new OpenFileDialog();

            d.InitialDirectory = Environment.CurrentDirectory;
            d.Filter           = "Image Files (*.BMP;*ICO;*.JPG;*JIF;*JPEG;*JPE;*.MNG;*PCX;*PNG;*TGA;*TIFF;*PSD;*GIF)|*.BMP;*ICO;*.JPG;*JIF;*JPEG;*JPE;*.MNG;*PCX;*PNG;*TGA;*TIFF;*PSD;*GIF";
            d.CheckFileExists  = true;

            if (d.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            var tga = new Targa();

            try
            {
                // get image bitmap
                bitmap = tga.Open(d.FileName);
                if (bitmap == null)
                {
                    throw new Exception();
                }
            }
            catch
            {
                MessageBox.Show(string.Format("Could not open image {0}", d.FileName), "Unknown image format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            // restrict image size to fixed width and height
            return(new Bitmap(bitmap, Helper.MaxWidth, Helper.MaxHeight));
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: yujintong/bni-icon-builder
        private void menuSave_Click(object sender, EventArgs e)
        {
            _saveCurrentIcon();

            var tga = new Targa();

            try
            {
                var images = _getImagesFromList();

                // generate full tga image
                var data = tga.CreateTga(images);
                // get icons
                var icons = _getIconItemsFromList();

                // save to file
                var bni = new BniFile();
                bni.Save(icons, data, FileName);

                HasModified = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: yujintong/bni-icon-builder
        private void menuOpen_Click(object sender, EventArgs e)
        {
            var d = new OpenFileDialog();

            d.InitialDirectory = Environment.CurrentDirectory;
            d.Filter           = "BNI Archive (*.bni)|*.bni";
            if (d.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // set global filename
            if (string.IsNullOrEmpty(FileName = d.FileName))
            {
                return;
            }

            try
            {
                customDrawListBox1.Items.Clear();

                var tga = new Targa();
                var bni = new BniFile();

                // load file to structure
                var bn = bni.Load(FileName);
                // get icon images
                var images = tga.SplitImage(bn.Data, 14);

                if (bn.Icons.Length != images.Length)
                {
                    MessageBox.Show(String.Format("Icons count ({0}) is not equals with images count ({1})", bn.Icons.Length, images.Length), "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                if (bn.Icons.Length == 0)
                {
                    throw new Exception(String.Format("No icons found"));
                }


                // put each image corresponding to it icon in bni structure
                for (int i = 0; i < bn.Icons.Length; i++)
                {
                    bn.Icons[i].Image = images[i];
                    customDrawListBox1.Items.Add(bn.Icons[i]);
                }

                // set first icon
                customDrawListBox1.SelectedIndex = 0;

                HasModified = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FileName = null;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: yujintong/bni-icon-builder
        private void menuSaveAs_Click(object sender, EventArgs e)
        {
            _saveCurrentIcon();

            var d = new SaveFileDialog();

            d.InitialDirectory = Environment.CurrentDirectory;
            d.Filter           = "BNI Archive (*.bni)|*.bni";
            d.CheckPathExists  = true;

            if (d.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var fileName = d.FileName;

            var tga = new Targa();

            try
            {
                var images = _getImagesFromList();

                // generate full tga image
                var data = tga.CreateTga(images);
                // get icons
                var icons = _getIconItemsFromList();

                // save to file
                var bni = new BniFile();
                bni.Save(icons, data, fileName);

                HasModified = false;
                MessageBox.Show(string.Format("File saved to {0}", fileName), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: yujintong/bni-icon-builder
        private void menuExport_Click(object sender, EventArgs e)
        {
            string fileName = null;
            string path     = null;

            var q = MessageBox.Show("Do you want to export all icons as a single image?", "Export As...", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

            // export single image
            if (q == DialogResult.Yes)
            {
                var d = new SaveFileDialog();
                d.InitialDirectory = Environment.CurrentDirectory;
                d.Filter           = "Targa image (*.tga)|*.tga";
                d.CheckPathExists  = true;

                if (d.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                fileName = d.FileName;
            }
            // export many images
            else
            {
                var d = new FolderBrowserDialog();
                d.SelectedPath = Environment.CurrentDirectory;
                if (d.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                path = d.SelectedPath;
            }


            var tga = new Targa();

            try
            {
                var images = _getImagesFromList();

                // export image to a file(s)
                if (fileName != null)
                {
                    tga.ExportTga(images, fileName);
                    MessageBox.Show(string.Format("Image saved to {0}", fileName), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    var    icons = _getIconItemsFromList();
                    var    files = new string[icons.Length];
                    string _name;
                    for (int i = 0; i < icons.Length; i++)
                    {
                        _name = icons[i].Flag > 0
                            ? string.Format("0x{0:x8}", icons[i].Flag)
                            : icons[i].Tag;
                        files[i] = Path.Combine(path, _name + ".tga");
                    }

                    tga.ExportTgaMany(images, files);
                    MessageBox.Show(string.Format("Images saved to {0}", path), "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }