Esempio n. 1
0
        private void exportAsTGAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.toolBox1.SelectedTab == null || this.toolBox1.SelectedTab.SelectedItem == null ||
                !(this.toolBox1.SelectedTab.SelectedItem.Object is Sprite))
            {
                return;
            }
            Sprite sprite     = (Sprite)this.toolBox1.SelectedTab.SelectedItem.Object;
            Regex  rgx        = new Regex("[^a-zA-Z0-9]");
            string spriteName = rgx.Replace(Path.GetFileNameWithoutExtension(sprite.Path), String.Empty);

            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.FileName   = String.Format("{0}.TGA", spriteName);
                dlg.DefaultExt = ".TGA";
                dlg.Filter     = "TGA|*.TGA";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                using (Bitmap bitmap = new Bitmap(sprite.Img))
                {
                    TgaWriter.WriteTga24Bits(bitmap, dlg.FileName);
                }
                MessageBox.Show("OK", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public void ExportAsTga(bool onlySelected = false)
        {
            if (this.Empty)
            {
                return;
            }
            Regex  rgx        = new Regex("[^a-zA-Z0-9]");
            string spriteName = rgx.Replace(Path.GetFileNameWithoutExtension(this.Text), String.Empty);

            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.FileName   = String.Format("{0}.TGA", spriteName);
                dlg.DefaultExt = ".TGA";
                dlg.Filter     = "TGA|*.TGA";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                using (Bitmap bitmap = this.GetBitmap(onlySelected))
                {
                    TgaWriter.WriteTga24Bits(bitmap, dlg.FileName);
                }
                MessageBox.Show("OK", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 3
0
 public static void WriteTga24Bits(Bitmap bitmap, string path, Color?transparentColor = null)
 {
     using (Stream file = File.Create(path))
     {
         TgaWriter.WriteTga24Bits(bitmap, file, transparentColor);
     }
 }
        private bool SaveMemorySpriteOnDisk()
        {
            List <Sprite> toSave = new List <Sprite>();
            string        folder = null;

            foreach (Control tile in this.panelGrid.Controls)
            {
                if (tile is Tile)
                {
                    if (String.IsNullOrEmpty(((Tile)tile).Sprite.Path))
                    {
                        toSave.Add(((Tile)tile).Sprite);
                    }
                    else if (folder == null)
                    {
                        folder = Path.GetDirectoryName(((Tile)tile).Sprite.Path);
                    }
                }
            }
            if (toSave.Count <= 0)
            {
                return(true);
            }
            if (MessageBox.Show("Some tiles image are not saved. Would you like to save them (Mandatory to save MAP) ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return(false);
            }
            using (FolderBrowserDialog dialog = new FolderBrowserDialog())
            {
                if (folder != null)
                {
                    dialog.SelectedPath = folder;
                }
                dialog.ShowNewFolderButton = true;
                dialog.Description         = "Please select the forder where tiles will be saved";
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }
                int  id            = 0;
                bool overrideImage = false;
                foreach (Sprite sprite in toSave)
                {
                    string path = Path.Combine(dialog.SelectedPath, String.Format("T{0}.TGA", id));
                    if (File.Exists(path))
                    {
                        if (!overrideImage)
                        {
                            if (MessageBox.Show("Some image already exists. Do you want to override them ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                            {
                                return(false);
                            }
                            overrideImage = true;
                        }
                        File.Delete(path);
                    }
                    using (Bitmap bitmap = new Bitmap(sprite.Img))
                    {
                        TgaWriter.WriteTga24Bits(bitmap, path);
                    }
                    ++id;
                    sprite.Path = path;
                }
            }
            return(true);
        }