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.Image2D Img) { byte[] idata; byte[] innerdata = Img.getRawData(); if (Img.is4bpp) { idata = new byte[innerdata.Length / 2]; for (int i = 0; i < idata.Length; i++) { idata[i] = (byte)((innerdata[i * 2] & 15) | (innerdata[i * 2 + 1] & 15) << 4); } } else { idata = (byte[])innerdata.Clone(); } return(idata); }