private void IconReplaceButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog od = new OpenFileDialog { Title = "Select image to replace icon", Filter = "Portable Network Graphics image|*.png|JPEG image|*.jpg|All file types|*.*", Multiselect = false, }; if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { NSMBe4.ROM.load(new NSMBe4.DSFileSystem.NitroROMFilesystem(MainWindow.ROMPath)); var f = NSMBe4.ROM.getLevelFile("banner"); var imgf = new NSMBe4.DSFileSystem.InlineFile(f, 32, 512, f.name); var palf = new NSMBe4.DSFileSystem.InlineFile(f, 544, 32, f.name); var i2d = new NSMBe4.Image2D(imgf, 32, true, false) as NSMBe4.PalettedImage; var ipal = new NSMBe4.FilePalette(palf); i2d.replaceImgAndPal(new Bitmap(od.FileName), ipal as NSMBe4.Palette); Array.Copy((i2d as NSMBe4.Image2D).getData(), MainWindow.LoadedROM.Banner.Banner.Image, 512); Array.Copy(ipal.getData(), MainWindow.LoadedROM.Banner.Banner.Pltt, 32); NSMBe4.ROM.close(); UpdateValues(); } catch { Utils.ShowMessage("An error ocurred trying to change the game's icon."); } } }
public static byte[] getData(this NSMBe4.FilePalette Palette) { var byteArrayOutputStream = new NSMBe4.ByteArrayOutputStream(); for (int i = 0; i < Palette.pal.Length; i++) { byteArrayOutputStream.writeUShort(NSMBe4.NSMBTileset.toRGB15(Palette.pal[i])); } return(byteArrayOutputStream.getArray()); }