完善预览图导出
This commit is contained in:
105
SpineViewer/Dialogs/ExportPreviewDialog.Designer.cs
generated
105
SpineViewer/Dialogs/ExportPreviewDialog.Designer.cs
generated
@@ -31,23 +31,18 @@
|
|||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExportPreviewDialog));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExportPreviewDialog));
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
tableLayoutPanel1 = new TableLayoutPanel();
|
tableLayoutPanel1 = new TableLayoutPanel();
|
||||||
|
propertyGrid = new PropertyGrid();
|
||||||
label4 = new Label();
|
label4 = new Label();
|
||||||
label1 = new Label();
|
label1 = new Label();
|
||||||
label2 = new Label();
|
|
||||||
label3 = new Label();
|
|
||||||
textBox_OutputDir = new TextBox();
|
textBox_OutputDir = new TextBox();
|
||||||
button_SelectOutputDir = new Button();
|
button_SelectOutputDir = new Button();
|
||||||
tableLayoutPanel2 = new TableLayoutPanel();
|
tableLayoutPanel2 = new TableLayoutPanel();
|
||||||
button_Ok = new Button();
|
button_Ok = new Button();
|
||||||
button_Cancel = new Button();
|
button_Cancel = new Button();
|
||||||
numericUpDown_Width = new NumericUpDown();
|
|
||||||
numericUpDown_Height = new NumericUpDown();
|
|
||||||
folderBrowserDialog = new FolderBrowserDialog();
|
folderBrowserDialog = new FolderBrowserDialog();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
tableLayoutPanel1.SuspendLayout();
|
tableLayoutPanel1.SuspendLayout();
|
||||||
tableLayoutPanel2.SuspendLayout();
|
tableLayoutPanel2.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Width).BeginInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Height).BeginInit();
|
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
@@ -57,7 +52,7 @@
|
|||||||
panel1.Location = new Point(0, 0);
|
panel1.Location = new Point(0, 0);
|
||||||
panel1.Name = "panel1";
|
panel1.Name = "panel1";
|
||||||
panel1.Padding = new Padding(50, 15, 50, 10);
|
panel1.Padding = new Padding(50, 15, 50, 10);
|
||||||
panel1.Size = new Size(919, 276);
|
panel1.Size = new Size(914, 482);
|
||||||
panel1.TabIndex = 2;
|
panel1.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// tableLayoutPanel1
|
// tableLayoutPanel1
|
||||||
@@ -68,27 +63,34 @@
|
|||||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle());
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle());
|
||||||
|
tableLayoutPanel1.Controls.Add(propertyGrid, 0, 2);
|
||||||
tableLayoutPanel1.Controls.Add(label4, 0, 0);
|
tableLayoutPanel1.Controls.Add(label4, 0, 0);
|
||||||
tableLayoutPanel1.Controls.Add(label1, 0, 1);
|
tableLayoutPanel1.Controls.Add(label1, 0, 1);
|
||||||
tableLayoutPanel1.Controls.Add(label2, 0, 2);
|
|
||||||
tableLayoutPanel1.Controls.Add(label3, 0, 3);
|
|
||||||
tableLayoutPanel1.Controls.Add(textBox_OutputDir, 1, 1);
|
tableLayoutPanel1.Controls.Add(textBox_OutputDir, 1, 1);
|
||||||
tableLayoutPanel1.Controls.Add(button_SelectOutputDir, 3, 1);
|
tableLayoutPanel1.Controls.Add(button_SelectOutputDir, 3, 1);
|
||||||
tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 4);
|
tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 3);
|
||||||
tableLayoutPanel1.Controls.Add(numericUpDown_Width, 1, 2);
|
|
||||||
tableLayoutPanel1.Controls.Add(numericUpDown_Height, 1, 3);
|
|
||||||
tableLayoutPanel1.Dock = DockStyle.Fill;
|
tableLayoutPanel1.Dock = DockStyle.Fill;
|
||||||
tableLayoutPanel1.Location = new Point(50, 15);
|
tableLayoutPanel1.Location = new Point(50, 15);
|
||||||
tableLayoutPanel1.Name = "tableLayoutPanel1";
|
tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
tableLayoutPanel1.RowCount = 5;
|
tableLayoutPanel1.RowCount = 4;
|
||||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
||||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
||||||
|
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
||||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
tableLayoutPanel1.Size = new Size(814, 457);
|
||||||
tableLayoutPanel1.RowStyles.Add(new RowStyle());
|
|
||||||
tableLayoutPanel1.Size = new Size(819, 251);
|
|
||||||
tableLayoutPanel1.TabIndex = 0;
|
tableLayoutPanel1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// propertyGrid
|
||||||
|
//
|
||||||
|
tableLayoutPanel1.SetColumnSpan(propertyGrid, 4);
|
||||||
|
propertyGrid.Dock = DockStyle.Fill;
|
||||||
|
propertyGrid.HelpVisible = false;
|
||||||
|
propertyGrid.Location = new Point(3, 97);
|
||||||
|
propertyGrid.Name = "propertyGrid";
|
||||||
|
propertyGrid.Size = new Size(808, 284);
|
||||||
|
propertyGrid.TabIndex = 1;
|
||||||
|
propertyGrid.ToolbarVisible = false;
|
||||||
|
//
|
||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
label4.AutoSize = true;
|
label4.AutoSize = true;
|
||||||
@@ -97,9 +99,9 @@
|
|||||||
label4.Location = new Point(15, 15);
|
label4.Location = new Point(15, 15);
|
||||||
label4.Margin = new Padding(15);
|
label4.Margin = new Padding(15);
|
||||||
label4.Name = "label4";
|
label4.Name = "label4";
|
||||||
label4.Size = new Size(789, 24);
|
label4.Size = new Size(784, 24);
|
||||||
label4.TabIndex = 11;
|
label4.TabIndex = 11;
|
||||||
label4.Text = "说明:导出的文件名与骨骼文件名相同";
|
label4.Text = "说明:输出文件夹为可选项,留空则将预览图输出到每个骨骼文件所在目录";
|
||||||
label4.TextAlign = ContentAlignment.MiddleCenter;
|
label4.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
@@ -112,40 +114,20 @@
|
|||||||
label1.TabIndex = 0;
|
label1.TabIndex = 0;
|
||||||
label1.Text = "输出文件夹:";
|
label1.Text = "输出文件夹:";
|
||||||
//
|
//
|
||||||
// label2
|
|
||||||
//
|
|
||||||
label2.Anchor = AnchorStyles.Right;
|
|
||||||
label2.AutoSize = true;
|
|
||||||
label2.Location = new Point(75, 100);
|
|
||||||
label2.Name = "label2";
|
|
||||||
label2.Size = new Size(32, 24);
|
|
||||||
label2.TabIndex = 1;
|
|
||||||
label2.Text = "宽:";
|
|
||||||
//
|
|
||||||
// label3
|
|
||||||
//
|
|
||||||
label3.Anchor = AnchorStyles.Right;
|
|
||||||
label3.AutoSize = true;
|
|
||||||
label3.Location = new Point(75, 136);
|
|
||||||
label3.Name = "label3";
|
|
||||||
label3.Size = new Size(32, 24);
|
|
||||||
label3.TabIndex = 2;
|
|
||||||
label3.Text = "高:";
|
|
||||||
//
|
|
||||||
// textBox_OutputDir
|
// textBox_OutputDir
|
||||||
//
|
//
|
||||||
tableLayoutPanel1.SetColumnSpan(textBox_OutputDir, 2);
|
tableLayoutPanel1.SetColumnSpan(textBox_OutputDir, 2);
|
||||||
textBox_OutputDir.Dock = DockStyle.Fill;
|
textBox_OutputDir.Dock = DockStyle.Fill;
|
||||||
textBox_OutputDir.Location = new Point(113, 57);
|
textBox_OutputDir.Location = new Point(113, 57);
|
||||||
textBox_OutputDir.Name = "textBox_OutputDir";
|
textBox_OutputDir.Name = "textBox_OutputDir";
|
||||||
textBox_OutputDir.Size = new Size(664, 30);
|
textBox_OutputDir.Size = new Size(660, 30);
|
||||||
textBox_OutputDir.TabIndex = 3;
|
textBox_OutputDir.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// button_SelectOutputDir
|
// button_SelectOutputDir
|
||||||
//
|
//
|
||||||
button_SelectOutputDir.AutoSize = true;
|
button_SelectOutputDir.AutoSize = true;
|
||||||
button_SelectOutputDir.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
button_SelectOutputDir.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
||||||
button_SelectOutputDir.Location = new Point(783, 57);
|
button_SelectOutputDir.Location = new Point(779, 57);
|
||||||
button_SelectOutputDir.Name = "button_SelectOutputDir";
|
button_SelectOutputDir.Name = "button_SelectOutputDir";
|
||||||
button_SelectOutputDir.Size = new Size(32, 34);
|
button_SelectOutputDir.Size = new Size(32, 34);
|
||||||
button_SelectOutputDir.TabIndex = 5;
|
button_SelectOutputDir.TabIndex = 5;
|
||||||
@@ -164,17 +146,18 @@
|
|||||||
tableLayoutPanel2.Controls.Add(button_Ok, 0, 0);
|
tableLayoutPanel2.Controls.Add(button_Ok, 0, 0);
|
||||||
tableLayoutPanel2.Controls.Add(button_Cancel, 1, 0);
|
tableLayoutPanel2.Controls.Add(button_Cancel, 1, 0);
|
||||||
tableLayoutPanel2.Dock = DockStyle.Bottom;
|
tableLayoutPanel2.Dock = DockStyle.Bottom;
|
||||||
tableLayoutPanel2.Location = new Point(3, 208);
|
tableLayoutPanel2.Location = new Point(3, 414);
|
||||||
|
tableLayoutPanel2.Margin = new Padding(3, 30, 3, 3);
|
||||||
tableLayoutPanel2.Name = "tableLayoutPanel2";
|
tableLayoutPanel2.Name = "tableLayoutPanel2";
|
||||||
tableLayoutPanel2.RowCount = 1;
|
tableLayoutPanel2.RowCount = 1;
|
||||||
tableLayoutPanel2.RowStyles.Add(new RowStyle());
|
tableLayoutPanel2.RowStyles.Add(new RowStyle());
|
||||||
tableLayoutPanel2.Size = new Size(813, 40);
|
tableLayoutPanel2.Size = new Size(808, 40);
|
||||||
tableLayoutPanel2.TabIndex = 10;
|
tableLayoutPanel2.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// button_Ok
|
// button_Ok
|
||||||
//
|
//
|
||||||
button_Ok.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
button_Ok.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
button_Ok.Location = new Point(264, 3);
|
button_Ok.Location = new Point(262, 3);
|
||||||
button_Ok.Margin = new Padding(3, 3, 30, 3);
|
button_Ok.Margin = new Padding(3, 3, 30, 3);
|
||||||
button_Ok.Name = "button_Ok";
|
button_Ok.Name = "button_Ok";
|
||||||
button_Ok.Size = new Size(112, 34);
|
button_Ok.Size = new Size(112, 34);
|
||||||
@@ -186,7 +169,7 @@
|
|||||||
// button_Cancel
|
// button_Cancel
|
||||||
//
|
//
|
||||||
button_Cancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
button_Cancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
button_Cancel.Location = new Point(436, 3);
|
button_Cancel.Location = new Point(434, 3);
|
||||||
button_Cancel.Margin = new Padding(30, 3, 3, 3);
|
button_Cancel.Margin = new Padding(30, 3, 3, 3);
|
||||||
button_Cancel.Name = "button_Cancel";
|
button_Cancel.Name = "button_Cancel";
|
||||||
button_Cancel.Size = new Size(112, 34);
|
button_Cancel.Size = new Size(112, 34);
|
||||||
@@ -195,30 +178,6 @@
|
|||||||
button_Cancel.UseVisualStyleBackColor = true;
|
button_Cancel.UseVisualStyleBackColor = true;
|
||||||
button_Cancel.Click += button_Cancel_Click;
|
button_Cancel.Click += button_Cancel_Click;
|
||||||
//
|
//
|
||||||
// numericUpDown_Width
|
|
||||||
//
|
|
||||||
numericUpDown_Width.Anchor = AnchorStyles.Left;
|
|
||||||
numericUpDown_Width.Location = new Point(113, 97);
|
|
||||||
numericUpDown_Width.Maximum = new decimal(new int[] { 4096, 0, 0, 0 });
|
|
||||||
numericUpDown_Width.Minimum = new decimal(new int[] { 32, 0, 0, 0 });
|
|
||||||
numericUpDown_Width.Name = "numericUpDown_Width";
|
|
||||||
numericUpDown_Width.Size = new Size(180, 30);
|
|
||||||
numericUpDown_Width.TabIndex = 12;
|
|
||||||
numericUpDown_Width.TextAlign = HorizontalAlignment.Right;
|
|
||||||
numericUpDown_Width.Value = new decimal(new int[] { 256, 0, 0, 0 });
|
|
||||||
//
|
|
||||||
// numericUpDown_Height
|
|
||||||
//
|
|
||||||
numericUpDown_Height.Anchor = AnchorStyles.Left;
|
|
||||||
numericUpDown_Height.Location = new Point(113, 133);
|
|
||||||
numericUpDown_Height.Maximum = new decimal(new int[] { 4096, 0, 0, 0 });
|
|
||||||
numericUpDown_Height.Minimum = new decimal(new int[] { 32, 0, 0, 0 });
|
|
||||||
numericUpDown_Height.Name = "numericUpDown_Height";
|
|
||||||
numericUpDown_Height.Size = new Size(180, 30);
|
|
||||||
numericUpDown_Height.TabIndex = 13;
|
|
||||||
numericUpDown_Height.TextAlign = HorizontalAlignment.Right;
|
|
||||||
numericUpDown_Height.Value = new decimal(new int[] { 256, 0, 0, 0 });
|
|
||||||
//
|
|
||||||
// folderBrowserDialog
|
// folderBrowserDialog
|
||||||
//
|
//
|
||||||
folderBrowserDialog.AddToRecent = false;
|
folderBrowserDialog.AddToRecent = false;
|
||||||
@@ -229,7 +188,7 @@
|
|||||||
AutoScaleDimensions = new SizeF(11F, 24F);
|
AutoScaleDimensions = new SizeF(11F, 24F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
CancelButton = button_Cancel;
|
CancelButton = button_Cancel;
|
||||||
ClientSize = new Size(919, 276);
|
ClientSize = new Size(914, 482);
|
||||||
Controls.Add(panel1);
|
Controls.Add(panel1);
|
||||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
Icon = (Icon)resources.GetObject("$this.Icon");
|
Icon = (Icon)resources.GetObject("$this.Icon");
|
||||||
@@ -239,14 +198,11 @@
|
|||||||
ShowInTaskbar = false;
|
ShowInTaskbar = false;
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "导出预览图";
|
Text = "导出预览图";
|
||||||
Load += ExportPreviewDialog_Load;
|
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
panel1.PerformLayout();
|
panel1.PerformLayout();
|
||||||
tableLayoutPanel1.ResumeLayout(false);
|
tableLayoutPanel1.ResumeLayout(false);
|
||||||
tableLayoutPanel1.PerformLayout();
|
tableLayoutPanel1.PerformLayout();
|
||||||
tableLayoutPanel2.ResumeLayout(false);
|
tableLayoutPanel2.ResumeLayout(false);
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Width).EndInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Height).EndInit();
|
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,15 +212,12 @@
|
|||||||
private TableLayoutPanel tableLayoutPanel1;
|
private TableLayoutPanel tableLayoutPanel1;
|
||||||
private Label label4;
|
private Label label4;
|
||||||
private Label label1;
|
private Label label1;
|
||||||
private Label label2;
|
|
||||||
private Label label3;
|
|
||||||
private TextBox textBox_OutputDir;
|
private TextBox textBox_OutputDir;
|
||||||
private Button button_SelectOutputDir;
|
private Button button_SelectOutputDir;
|
||||||
private TableLayoutPanel tableLayoutPanel2;
|
private TableLayoutPanel tableLayoutPanel2;
|
||||||
private Button button_Ok;
|
private Button button_Ok;
|
||||||
private Button button_Cancel;
|
private Button button_Cancel;
|
||||||
private NumericUpDown numericUpDown_Width;
|
|
||||||
private NumericUpDown numericUpDown_Height;
|
|
||||||
private FolderBrowserDialog folderBrowserDialog;
|
private FolderBrowserDialog folderBrowserDialog;
|
||||||
|
private PropertyGrid propertyGrid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -12,59 +13,58 @@ namespace SpineViewer.Dialogs
|
|||||||
{
|
{
|
||||||
public partial class ExportPreviewDialog: Form
|
public partial class ExportPreviewDialog: Form
|
||||||
{
|
{
|
||||||
// TODO: 用单独的结果包装类
|
/// <summary>
|
||||||
public string OutputDir { get; private set; }
|
/// 对话框结果
|
||||||
public uint PreviewWidth { get; private set; }
|
/// </summary>
|
||||||
public uint PreviewHeight { get; private set; }
|
public readonly ExportPreviewDialogResult Result = new();
|
||||||
|
|
||||||
public ExportPreviewDialog()
|
public ExportPreviewDialog()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
propertyGrid.SelectedObject = Result;
|
||||||
|
|
||||||
private void ExportPreviewDialog_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
button_SelectOutputDir_Click(sender, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_SelectOutputDir_Click(object sender, EventArgs e)
|
private void button_SelectOutputDir_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
folderBrowserDialog.InitialDirectory = textBox_OutputDir.Text;
|
folderBrowserDialog.InitialDirectory = textBox_OutputDir.Text;
|
||||||
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
|
||||||
{
|
return;
|
||||||
textBox_OutputDir.Text = Path.GetFullPath(folderBrowserDialog.SelectedPath);
|
textBox_OutputDir.Text = Path.GetFullPath(folderBrowserDialog.SelectedPath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_Ok_Click(object sender, EventArgs e)
|
private void button_Ok_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var outputDir = textBox_OutputDir.Text;
|
var outputDir = textBox_OutputDir.Text;
|
||||||
if (File.Exists(outputDir))
|
if (string.IsNullOrEmpty(outputDir))
|
||||||
{
|
{
|
||||||
MessageBox.Info("输出文件夹无效");
|
Result.OutputDir = null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (!Directory.Exists(outputDir))
|
|
||||||
{
|
{
|
||||||
if (MessageBox.Quest($"文件夹 {outputDir} 不存在,是否创建?") != DialogResult.OK)
|
if (File.Exists(outputDir))
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(outputDir);
|
MessageBox.Info("输出文件夹无效");
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Program.Logger.Error(ex.ToString());
|
|
||||||
MessageBox.Error(ex.ToString(), "文件夹创建失败");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
OutputDir = Path.GetFullPath(outputDir);
|
if (!Directory.Exists(outputDir))
|
||||||
PreviewWidth = (uint)numericUpDown_Width.Value;
|
{
|
||||||
PreviewHeight = (uint)numericUpDown_Height.Value;
|
if (MessageBox.Quest($"文件夹 {outputDir} 不存在,是否创建?") != DialogResult.OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(outputDir);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Program.Logger.Error(ex.ToString());
|
||||||
|
MessageBox.Error(ex.ToString(), "文件夹创建失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Result.OutputDir = Path.GetFullPath(outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
@@ -74,4 +74,83 @@ namespace SpineViewer.Dialogs
|
|||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ExportPreviewDialogResult
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 输出路径
|
||||||
|
/// </summary>
|
||||||
|
[Browsable(false)]
|
||||||
|
public string? OutputDir { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 预览图格式
|
||||||
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(ImageFormatConverter))]
|
||||||
|
[Category("导出参数"), DisplayName("预览图格式")]
|
||||||
|
public ImageFormat ImageFormat
|
||||||
|
{
|
||||||
|
get => imageFormat;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == ImageFormat.MemoryBmp) value = ImageFormat.Bmp;
|
||||||
|
imageFormat = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private ImageFormat imageFormat = ImageFormat.Png;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 预览图分辨率
|
||||||
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(SizeConverter))]
|
||||||
|
[Category("导出参数"), DisplayName("分辨率")]
|
||||||
|
public Size Resolution
|
||||||
|
{
|
||||||
|
get => resolution;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.Width <= 0) value.Width = 128;
|
||||||
|
if (value.Height <= 0) value.Height = 128;
|
||||||
|
resolution = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Size resolution = new(512, 512);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 四周填充像素值
|
||||||
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(PaddingConverter))]
|
||||||
|
[Category("导出参数"), DisplayName("四周填充像素值")]
|
||||||
|
public Padding Padding
|
||||||
|
{
|
||||||
|
get => padding;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.Left <= 0) value.Left = 10;
|
||||||
|
if (value.Right <= 0) value.Right = 10;
|
||||||
|
if (value.Top <= 0) value.Top = 10;
|
||||||
|
if (value.Bottom <= 0) value.Bottom = 10;
|
||||||
|
padding = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Padding padding = new(1);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// DPI
|
||||||
|
/// </summary>
|
||||||
|
[TypeConverter(typeof(SizeFConverter))]
|
||||||
|
[Category("导出参数"), DisplayName("DPI")]
|
||||||
|
public SizeF DPI
|
||||||
|
{
|
||||||
|
get => dpi;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.Width <= 0) value.Width = 144;
|
||||||
|
if (value.Height <= 0) value.Height = 144;
|
||||||
|
dpi = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private SizeF dpi = new(144, 144);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
64
SpineViewer/ExportHelper.cs
Normal file
64
SpineViewer/ExportHelper.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using FFMpegCore.Pipes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
||||||
|
|
||||||
|
namespace SpineViewer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// SFML.Graphics.Image 帧对象包装类
|
||||||
|
/// </summary>
|
||||||
|
public class SFMLImageVideoFrame(SFML.Graphics.Image image) : IVideoFrame, IDisposable
|
||||||
|
{
|
||||||
|
public int Width => (int)image.Size.X;
|
||||||
|
public int Height => (int)image.Size.Y;
|
||||||
|
public string Format => "rgba";
|
||||||
|
public void Serialize(Stream pipe) => pipe.Write(image.Pixels);
|
||||||
|
public async Task SerializeAsync(Stream pipe, CancellationToken token) => await pipe.WriteAsync(image.Pixels, token);
|
||||||
|
public void Dispose() => image.Dispose();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save the contents of the image to a file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Path of the file to save (overwritten if already exist)</param>
|
||||||
|
/// <returns>True if saving was successful</returns>
|
||||||
|
public bool SaveToFile(string filename) => image.SaveToFile(filename);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save the image to a buffer in memory The format of the image must be specified.
|
||||||
|
/// The supported image formats are bmp, png, tga and jpg. This function fails if
|
||||||
|
/// the image is empty, or if the format was invalid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="output">Byte array filled with encoded data</param>
|
||||||
|
/// <param name="format">Encoding format to use</param>
|
||||||
|
/// <returns>True if saving was successful</returns>
|
||||||
|
public bool SaveToMemory(out byte[] output, string format) => image.SaveToMemory(out output, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 为帧导出创建的辅助类
|
||||||
|
/// </summary>
|
||||||
|
public static class ExportHelper
|
||||||
|
{
|
||||||
|
public static Bitmap CopyToBitmap(this SFML.Graphics.Texture tex)
|
||||||
|
{
|
||||||
|
using var img = tex.CopyToImage();
|
||||||
|
img.SaveToMemory(out var imgBuffer, "bmp");
|
||||||
|
using var stream = new MemoryStream(imgBuffer);
|
||||||
|
return new Bitmap(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SFMLImageVideoFrame CopyToFrame(this SFML.Graphics.Texture tex) => new(tex.CopyToImage());
|
||||||
|
|
||||||
|
public static string GetSuffix(this ImageFormat imageFormat)
|
||||||
|
{
|
||||||
|
if (imageFormat == ImageFormat.Icon) return ".ico";
|
||||||
|
else if (imageFormat == ImageFormat.Exif) return ".jpg";
|
||||||
|
else return $".{imageFormat.ToString().ToLower()}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,7 +106,7 @@ namespace SpineViewer
|
|||||||
|
|
||||||
var progressDialog = new Dialogs.ProgressDialog();
|
var progressDialog = new Dialogs.ProgressDialog();
|
||||||
progressDialog.DoWork += ExportPreview_Work;
|
progressDialog.DoWork += ExportPreview_Work;
|
||||||
progressDialog.RunWorkerAsync(saveDialog);
|
progressDialog.RunWorkerAsync(saveDialog.Result);
|
||||||
progressDialog.ShowDialog();
|
progressDialog.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,17 +294,15 @@ namespace SpineViewer
|
|||||||
private void ExportPreview_Work(object? sender, DoWorkEventArgs e)
|
private void ExportPreview_Work(object? sender, DoWorkEventArgs e)
|
||||||
{
|
{
|
||||||
var worker = sender as BackgroundWorker;
|
var worker = sender as BackgroundWorker;
|
||||||
var arguments = e.Argument as Dialogs.ExportPreviewDialog;
|
var arguments = e.Argument as Dialogs.ExportPreviewDialogResult;
|
||||||
var outputDir = arguments.OutputDir;
|
|
||||||
var width = arguments.PreviewWidth;
|
|
||||||
var height = arguments.PreviewHeight;
|
|
||||||
// TODO: 增加填充参数
|
|
||||||
var paddingL = 1u;
|
|
||||||
var paddingR = 1u;
|
|
||||||
var paddingT = 1u;
|
|
||||||
var paddingB = 1u;
|
|
||||||
|
|
||||||
var tex = new SFML.Graphics.RenderTexture(width, height);
|
var outputDir = arguments.OutputDir;
|
||||||
|
var imageFormat = arguments.ImageFormat;
|
||||||
|
var resolution = arguments.Resolution;
|
||||||
|
var padding = arguments.Padding;
|
||||||
|
var dpi = arguments.DPI;
|
||||||
|
|
||||||
|
var tex = new SFML.Graphics.RenderTexture((uint)resolution.Width, (uint)resolution.Height);
|
||||||
|
|
||||||
int success = 0;
|
int success = 0;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
@@ -323,18 +321,23 @@ namespace SpineViewer
|
|||||||
}
|
}
|
||||||
|
|
||||||
var spine = spines[i];
|
var spine = spines[i];
|
||||||
|
var filename = $"(preview) {spine.Name}{imageFormat.GetSuffix()}"; // 加上 preview 是为了防止覆盖同名的 png 文件
|
||||||
|
var savePath = outputDir is null ? Path.Combine(spine.AssetsDir, filename) : Path.Combine(outputDir, filename);
|
||||||
|
|
||||||
var tmp = spine.CurrentAnimation;
|
var tmp = spine.CurrentAnimation;
|
||||||
spine.CurrentAnimation = Spine.Spine.EMPTY_ANIMATION;
|
spine.CurrentAnimation = Spine.Spine.EMPTY_ANIMATION;
|
||||||
tex.SetView(spine.GetInitView(width, height, paddingL, paddingR, paddingT, paddingB));
|
tex.SetView(spine.GetInitView(resolution, padding));
|
||||||
tex.Clear(SFML.Graphics.Color.Transparent);
|
tex.Clear(SFML.Graphics.Color.Transparent);
|
||||||
tex.Draw(spine);
|
tex.Draw(spine);
|
||||||
tex.Display();
|
tex.Display();
|
||||||
spine.CurrentAnimation = tmp;
|
spine.CurrentAnimation = tmp;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var img = tex.Texture.CopyToImage())
|
using (var img = new Bitmap(tex.Texture.CopyToBitmap()))
|
||||||
{
|
{
|
||||||
img.SaveToFile(Path.Combine(outputDir, $"{spine.Name}.png"));
|
img.SetResolution(dpi.Width, dpi.Height);
|
||||||
|
img.Save(savePath, imageFormat);
|
||||||
}
|
}
|
||||||
success++;
|
success++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user