private void Import_Click(object sender, RoutedEventArgs e) { UndertaleEmbeddedTexture target = DataContext as UndertaleEmbeddedTexture; OpenFileDialog dlg = new OpenFileDialog(); dlg.DefaultExt = ".png"; dlg.Filter = "PNG files (.png)|*.png|All files|*"; if (dlg.ShowDialog() == true) { try { Bitmap bmp; using (var ms = new MemoryStream(TextureWorker.ReadTextureBlob(dlg.FileName))) { bmp = new Bitmap(ms); } bmp.SetResolution(96.0F, 96.0F); var width = (uint)bmp.Width; var height = (uint)bmp.Height; if ((width & (width - 1)) != 0 || (height & (height - 1)) != 0) { mainWindow.ShowWarning("WARNING: texture page dimensions are not powers of 2. Sprite blurring is very likely in game.", "Unexpected texture dimensions"); } using (var stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); target.TextureData.TextureBlob = stream.ToArray(); TexWidth.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); TexHeight.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); } } catch (Exception ex) { mainWindow.ShowError("Failed to import file: " + ex.Message, "Failed to import file"); } } }
private void ExportAllSpine(SaveFileDialog dlg, UndertaleSprite sprite) { mainWindow.ShowWarning("This seems to be a Spine sprite, .json and .atlas files will be exported together with the frames. " + "PLEASE EDIT THEM CAREFULLY! SOME MANUAL EDITING OF THE JSON MAY BE REQUIRED! THE DATA IS EXPORTED AS-IS.", "Spine warning"); if (dlg.ShowDialog() == true) { try { string dir = System.IO.Path.GetDirectoryName(dlg.FileName); string name = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); string path = System.IO.Path.Combine(dir, name); string ext = System.IO.Path.GetExtension(dlg.FileName); if (sprite.SpineTextures.Count > 0) { Directory.CreateDirectory(path); // textures foreach (var tex in sprite.SpineTextures.Select((tex, id) => new { id, tex })) { try { File.WriteAllBytes(System.IO.Path.Combine(path, tex.id + ext), tex.tex.PNGBlob); } catch (Exception ex) { mainWindow.ShowError("Failed to export file: " + ex.Message, "Failed to export file"); } } // json and atlas File.WriteAllText(System.IO.Path.Combine(path, "spine.json"), sprite.SpineJSON); File.WriteAllText(System.IO.Path.Combine(path, "spine.atlas"), sprite.SpineAtlas); } } catch (Exception ex) { mainWindow.ShowError("Failed to export: " + ex.Message, "Failed to export sprite"); } } }