private void UI_ImportTextureButton_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "All Supported Files|*.tex;*.png|Texture|*.tex|Supported Image Files|*.png"; if (ofd.ShowDialog() == true) { if (ofd.FileName.ToLower(CultureInfo.GetCultureInfo("en-US")).EndsWith(".tex")) { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load new Texture newTexture.Load(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Import Texture into PCK PCKFontArchive.ReplaceFile(textureFilePath, File.ReadAllBytes(ofd.FileName)); // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } else { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load Image to Texture newTexture.LoadSheetImage(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Save Texture to PCK using (var stream = new MemoryStream()) { newTexture.Save(stream); PCKFontArchive.ReplaceFile(textureFilePath, stream.ToArray()); } // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } } }