Beispiel #1
0
 private void fromMDPaletteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog fd = new OpenFileDialog())
     {
         fd.DefaultExt       = "png";
         fd.Filter           = "Palette Files|*.bin";
         fd.RestoreDirectory = true;
         if (fd.ShowDialog(this) == DialogResult.OK)
         {
             byte[]  file   = File.ReadAllBytes(fd.FileName);
             Color[] colors = new Color[file.Length / 2];
             for (int i = 0; i < colors.Length; i++)
             {
                 colors[i] = Color.FromArgb(((file[(i * 2) + 1]) & 0xF) << 4, (file[(i * 2) + 1]) & 0xF0, ((file[i * 2]) & 0xF) << 4);
             }
             using (PaletteImportDialog pd = new PaletteImportDialog(colors))
                 if (pd.ShowDialog(this) == DialogResult.OK)
                 {
                     palette = pd.palette;
                     PalettePanel.Invalidate();
                     SpritePicture.Invalidate();
                     tileList1.Invalidate();
                     foreach (ToolStripMenuItem item in palettesToolStripMenuItem.DropDownItems)
                     {
                         item.Checked = false;
                     }
                 }
         }
     }
 }
Beispiel #2
0
 private void fromImageToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog fd = new OpenFileDialog())
     {
         fd.DefaultExt       = "png";
         fd.Filter           = "Image Files|*.bmp;*.png;*.jpg;*.gif";
         fd.RestoreDirectory = true;
         if (fd.ShowDialog(this) == DialogResult.OK)
         {
             Color[] colors;
             using (Bitmap bmp = new Bitmap(fd.FileName))
                 colors = bmp.Palette.Entries;
             using (PaletteImportDialog pd = new PaletteImportDialog(colors))
                 if (pd.ShowDialog(this) == DialogResult.OK)
                 {
                     palette = pd.palette;
                     PalettePanel.Invalidate();
                     SpritePicture.Invalidate();
                     tileList1.Invalidate();
                     foreach (ToolStripMenuItem item in palettesToolStripMenuItem.DropDownItems)
                     {
                         item.Checked = false;
                     }
                 }
         }
     }
 }