void btnLoadSheet_Click(object sender, EventArgs e) { if (OpenPngs.Enabled == false) { return; } OpenPngs.Enabled = false; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Select a sprite sheet"; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png"; openFileDialog.ShowHelp = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { OpenPngs.Enabled = true; return; } Bitmap image = new Bitmap(openFileDialog.FileName); if ((image.Width != 256) || (image.Height != 64)) { MessageBox.Show("The sprite sheet should be 256x64."); return; } IndexedBitmapHandler Handler = new IndexedBitmapHandler(); image = Handler.Convert(image, PixelFormat.Format8bppIndexed); image.Palette = StandardizeColors(image); Bitmap[] tiles = Handler.Split(image, 64, 64); SpriteSet sprites = new SpriteSet(); bool[] used = Handler.IsUsed(tiles[0]); used = Handler.IsUsed(tiles[2], used); Bitmap temp = Handler.ShrinkPalette(tiles[0], used); sprites.Normal = temp.Palette; temp = Handler.Resize(temp, 8, 8, 8, 8); temp = Handler.Concat(temp, temp); sprites.Sprites[2] = temp; sprites.Sprites[3] = temp; temp = Handler.ShrinkPalette(tiles[2], used); temp = Handler.Resize(temp, 8, 8, 8, 8); if (DPCheck.Checked) { temp = Handler.Resize(temp, 0, 0, 0, 80); } else { temp = Handler.Concat(temp, temp); } sprites.Sprites[0] = temp; sprites.Sprites[1] = temp; temp = Handler.ShrinkPalette(tiles[1], used); temp = Handler.Resize(temp, 8, 8, 8, 8); temp = Handler.Concat(temp, temp); sprites.Shiny = Handler.AlternatePalette(sprites.Sprites[2], temp); CurrentSprites = sprites; OpenPngs.Enabled = true; LoadImages(); }
Bitmap CheckSize(Bitmap image, string filename, string name, int spritenumber = 2) { DialogResult yesno; IndexedBitmapHandler Handler = new IndexedBitmapHandler(); if (image.PixelFormat != PixelFormat.Format8bppIndexed) { if (AutoConvert.Checked) { yesno = DialogResult.Yes; } else { yesno = MessageBox.Show(filename + " is not 8bpp Indexed! Attempt conversion?", "Incompatible image format", MessageBoxButtons.YesNo); } if (yesno != DialogResult.Yes) { return(null); } image = Handler.Convert(image, PixelFormat.Format8bppIndexed); if (image == null) { return(null); } if ((image.PixelFormat != PixelFormat.Format8bppIndexed) || (image.Palette == null)) { MessageBox.Show("Conversion failed.", "Failed"); return(null); } } if (((image.Height != 64) && (image.Height != 80)) || ((image.Width != 64) && (image.Width != 80) && (image.Width != 160))) { int imagescale = 0; if (UseShrinking.Checked) { if ((image.Width / 64 == image.Height / 64) && (image.Width % 64 == 0) && (image.Height % 64 == 0)) { imagescale = image.Width / 64; } if ((image.Width / 80 == image.Height / 80) && (image.Width % 80 == 0) && (image.Height % 80 == 0)) { imagescale = image.Width / 80; } if ((image.Width / 160 == image.Height / 80) && (image.Width % 160 == 0) && (image.Height % 80 == 0)) { imagescale = image.Width / 160; } if (imagescale > 1) { yesno = MessageBox.Show(filename + " is too large. Attempt to shrink?", "Too large", MessageBoxButtons.YesNo); if (yesno == DialogResult.Yes) { image = Handler.ShrinkImage(image, imagescale, imagescale); } else { imagescale = 0; } } } if (imagescale == 0) { yesno = MessageBox.Show(filename + " size not recognized. Use Canvas Splitter?", "Unrecognized size", MessageBoxButtons.YesNo); if (yesno != DialogResult.Yes) { return(null); } SizeChooser Chooser = new SizeChooser(); DialogResult success = Chooser.ShowDialog(); int sizeChoice = Chooser.choice; Chooser.Dispose(); if (success == DialogResult.Cancel) { return(null); } int a = 80; int b = 80; if (sizeChoice == 0) { a = 64; b = 64; } if (sizeChoice == 2) { a = 160; } if ((image.Width < a) || (image.Height < b)) { MessageBox.Show("Image is too small"); return(null); } Bitmap[] tiles = Handler.Split(image, a, b); SpriteCropper Cropper = new SpriteCropper(tiles, name); success = Cropper.ShowDialog(); if (success == DialogResult.Cancel) { return(null); } image = Cropper.Chosen; Cropper.Dispose(); } } if (AutoColor.Checked) { image.Palette = StandardizeColors(image); } byte check = Handler.PaletteSize(image); if (check > 16) { yesno = MessageBox.Show("Image's palette contains more than sixteen colors. Attempt to shrink?", "Improper palette size", MessageBoxButtons.YesNo); if (yesno == DialogResult.Yes) { image = Handler.ShrinkPalette(image); check = Handler.PaletteSize(image); if (check > 16) { MessageBox.Show("Palette still too large. Image will not save correctly.", "Failed"); } } } if (image.Height == 64 && image.Width == 64) { image = Handler.Resize(image, 8, 8, 8, 8); } if (image.Height == 80 && image.Width == 80) { if ((spritenumber < 2) && (DPCheck.Checked == true)) { image = Handler.Resize(image, 0, 0, 0, 80); } else { image = Handler.Concat(image, image); } } if (image.Height == 80 && image.Width == 160) { return(image); } return(null); }