UI优化:改名文档扫描王、去掉质量选项、预览放大、智能文件名
- 软件名称改为"文档扫描王" - 去掉JPEG质量选项,改用PNG无损写入PDF - 预览区域从685x190放大到710x440 - 窗口高度从600增到820 - 输出文件名:图片输入→时间戳.pdf,PDF输入→modify_原名.pdf - 删除GetJpegCodec等不再需要的代码 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -548,7 +548,7 @@ public static class PdfHelper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将多张图像保存为单个PDF
|
/// 将多张图像保存为单个PDF
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void SaveImagesToPdf(List<Bitmap> images, string outputPath, int jpegQuality)
|
public static void SaveImagesToPdf(List<Bitmap> images, string outputPath)
|
||||||
{
|
{
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
PdfWriter writer = null;
|
PdfWriter writer = null;
|
||||||
@@ -573,11 +573,7 @@ public static class PdfHelper
|
|||||||
byte[] imgBytes;
|
byte[] imgBytes;
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
EncoderParameters ep = new EncoderParameters(1);
|
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
ep.Param[0] = new EncoderParameter(
|
|
||||||
System.Drawing.Imaging.Encoder.Quality, (long)jpegQuality);
|
|
||||||
ImageCodecInfo codec = GetJpegCodec();
|
|
||||||
bmp.Save(ms, codec, ep);
|
|
||||||
imgBytes = ms.ToArray();
|
imgBytes = ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -595,15 +591,6 @@ public static class PdfHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImageCodecInfo GetJpegCodec()
|
|
||||||
{
|
|
||||||
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
|
|
||||||
for (int i = 0; i < codecs.Length; i++)
|
|
||||||
{
|
|
||||||
if (codecs[i].FormatID == ImageFormat.Jpeg.Guid) return codecs[i];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -614,7 +601,6 @@ public class ScannerForm : Form
|
|||||||
private ListBox lstFiles;
|
private ListBox lstFiles;
|
||||||
private Button btnAddImages, btnAddPdf, btnRemove, btnClear;
|
private Button btnAddImages, btnAddPdf, btnRemove, btnClear;
|
||||||
private Button btnMoveUp, btnMoveDown, btnProcess;
|
private Button btnMoveUp, btnMoveDown, btnProcess;
|
||||||
private NumericUpDown nudQuality;
|
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private Label lblStatus;
|
private Label lblStatus;
|
||||||
private PictureBox picPreview;
|
private PictureBox picPreview;
|
||||||
@@ -629,8 +615,8 @@ public class ScannerForm : Form
|
|||||||
|
|
||||||
private void InitUI()
|
private void InitUI()
|
||||||
{
|
{
|
||||||
this.Text = "文档扫描增强工具 v2";
|
this.Text = "文档扫描王";
|
||||||
this.Size = new System.Drawing.Size(720, 600);
|
this.Size = new System.Drawing.Size(750, 820);
|
||||||
this.StartPosition = FormStartPosition.CenterScreen;
|
this.StartPosition = FormStartPosition.CenterScreen;
|
||||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
this.MaximizeBox = false;
|
this.MaximizeBox = false;
|
||||||
@@ -731,47 +717,26 @@ public class ScannerForm : Form
|
|||||||
};
|
};
|
||||||
this.Controls.Add(btnMoveDown);
|
this.Controls.Add(btnMoveDown);
|
||||||
|
|
||||||
// JPEG质量
|
// 提示
|
||||||
GroupBox grp = new GroupBox();
|
Label lblHint = new Label();
|
||||||
grp.Text = "输出设置";
|
lblHint.Text = "(自动执行:透视矫正 → 倾斜校正 → 增强美化,一步到位)";
|
||||||
grp.Location = new System.Drawing.Point(15, 222);
|
lblHint.Location = new System.Drawing.Point(15, 225);
|
||||||
grp.Size = new System.Drawing.Size(685, 55);
|
lblHint.AutoSize = true;
|
||||||
grp.Font = new System.Drawing.Font("微软雅黑", 9f);
|
lblHint.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
|
||||||
this.Controls.Add(grp);
|
lblHint.Font = new System.Drawing.Font("微软雅黑", 8f);
|
||||||
|
this.Controls.Add(lblHint);
|
||||||
|
|
||||||
Label lblQ = new Label();
|
// 预览(正方形)
|
||||||
lblQ.Text = "PDF图像质量:";
|
|
||||||
lblQ.Location = new System.Drawing.Point(15, 23);
|
|
||||||
lblQ.AutoSize = true;
|
|
||||||
grp.Controls.Add(lblQ);
|
|
||||||
|
|
||||||
nudQuality = new NumericUpDown();
|
|
||||||
nudQuality.Location = new System.Drawing.Point(110, 20);
|
|
||||||
nudQuality.Size = new System.Drawing.Size(60, 25);
|
|
||||||
nudQuality.Minimum = 50;
|
|
||||||
nudQuality.Maximum = 100;
|
|
||||||
nudQuality.Value = 92;
|
|
||||||
grp.Controls.Add(nudQuality);
|
|
||||||
|
|
||||||
Label lblQH = new Label();
|
|
||||||
lblQH.Text = "(自动执行:透视矫正 → 倾斜校正 → 增强美化,一步到位)";
|
|
||||||
lblQH.Location = new System.Drawing.Point(180, 23);
|
|
||||||
lblQH.AutoSize = true;
|
|
||||||
lblQH.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100);
|
|
||||||
lblQH.Font = new System.Drawing.Font("微软雅黑", 8f);
|
|
||||||
grp.Controls.Add(lblQH);
|
|
||||||
|
|
||||||
// 预览
|
|
||||||
Label lblPrev = new Label();
|
Label lblPrev = new Label();
|
||||||
lblPrev.Text = "预览:";
|
lblPrev.Text = "预览:";
|
||||||
lblPrev.Location = new System.Drawing.Point(15, 285);
|
lblPrev.Location = new System.Drawing.Point(15, 248);
|
||||||
lblPrev.AutoSize = true;
|
lblPrev.AutoSize = true;
|
||||||
lblPrev.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Bold);
|
lblPrev.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Bold);
|
||||||
this.Controls.Add(lblPrev);
|
this.Controls.Add(lblPrev);
|
||||||
|
|
||||||
picPreview = new PictureBox();
|
picPreview = new PictureBox();
|
||||||
picPreview.Location = new System.Drawing.Point(15, 308);
|
picPreview.Location = new System.Drawing.Point(15, 270);
|
||||||
picPreview.Size = new System.Drawing.Size(685, 190);
|
picPreview.Size = new System.Drawing.Size(710, 440);
|
||||||
picPreview.SizeMode = PictureBoxSizeMode.Zoom;
|
picPreview.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
picPreview.BorderStyle = BorderStyle.FixedSingle;
|
picPreview.BorderStyle = BorderStyle.FixedSingle;
|
||||||
picPreview.BackColor = System.Drawing.Color.White;
|
picPreview.BackColor = System.Drawing.Color.White;
|
||||||
@@ -779,20 +744,20 @@ public class ScannerForm : Form
|
|||||||
|
|
||||||
// 底部
|
// 底部
|
||||||
progressBar = new ProgressBar();
|
progressBar = new ProgressBar();
|
||||||
progressBar.Location = new System.Drawing.Point(15, 510);
|
progressBar.Location = new System.Drawing.Point(15, 722);
|
||||||
progressBar.Size = new System.Drawing.Size(480, 25);
|
progressBar.Size = new System.Drawing.Size(510, 25);
|
||||||
this.Controls.Add(progressBar);
|
this.Controls.Add(progressBar);
|
||||||
|
|
||||||
lblStatus = new Label();
|
lblStatus = new Label();
|
||||||
lblStatus.Text = "就绪 - 添加文件后点击处理";
|
lblStatus.Text = "就绪 - 添加文件后点击处理";
|
||||||
lblStatus.Location = new System.Drawing.Point(15, 538);
|
lblStatus.Location = new System.Drawing.Point(15, 752);
|
||||||
lblStatus.Size = new System.Drawing.Size(480, 20);
|
lblStatus.Size = new System.Drawing.Size(510, 20);
|
||||||
lblStatus.ForeColor = System.Drawing.Color.DarkGray;
|
lblStatus.ForeColor = System.Drawing.Color.DarkGray;
|
||||||
this.Controls.Add(lblStatus);
|
this.Controls.Add(lblStatus);
|
||||||
|
|
||||||
btnProcess = new Button();
|
btnProcess = new Button();
|
||||||
btnProcess.Text = "一键处理并导出PDF";
|
btnProcess.Text = "一键处理并导出PDF";
|
||||||
btnProcess.Location = new System.Drawing.Point(510, 508);
|
btnProcess.Location = new System.Drawing.Point(540, 720);
|
||||||
btnProcess.Size = new System.Drawing.Size(190, 35);
|
btnProcess.Size = new System.Drawing.Size(190, 35);
|
||||||
btnProcess.Font = new System.Drawing.Font("微软雅黑", 10f, System.Drawing.FontStyle.Bold);
|
btnProcess.Font = new System.Drawing.Font("微软雅黑", 10f, System.Drawing.FontStyle.Bold);
|
||||||
btnProcess.BackColor = System.Drawing.Color.FromArgb(0, 120, 215);
|
btnProcess.BackColor = System.Drawing.Color.FromArgb(0, 120, 215);
|
||||||
@@ -867,14 +832,24 @@ public class ScannerForm : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 默认输出文件名
|
||||||
|
string defaultName;
|
||||||
|
if (isPdfInput)
|
||||||
|
{
|
||||||
|
defaultName = "modify_" + Path.GetFileName(inputFiles[0]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
defaultName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
|
||||||
|
}
|
||||||
|
|
||||||
SaveFileDialog sfd = new SaveFileDialog();
|
SaveFileDialog sfd = new SaveFileDialog();
|
||||||
sfd.Title = "保存处理后的PDF";
|
sfd.Title = "保存处理后的PDF";
|
||||||
sfd.Filter = "PDF|*.pdf";
|
sfd.Filter = "PDF|*.pdf";
|
||||||
sfd.FileName = "scanned_output.pdf";
|
sfd.FileName = defaultName;
|
||||||
if (sfd.ShowDialog() != DialogResult.OK) return;
|
if (sfd.ShowDialog() != DialogResult.OK) return;
|
||||||
|
|
||||||
string outputPath = sfd.FileName;
|
string outputPath = sfd.FileName;
|
||||||
int quality = (int)nudQuality.Value;
|
|
||||||
SetUI(false);
|
SetUI(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -927,7 +902,7 @@ public class ScannerForm : Form
|
|||||||
// 生成PDF
|
// 生成PDF
|
||||||
lblStatus.Text = "正在生成PDF...";
|
lblStatus.Text = "正在生成PDF...";
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
PdfHelper.SaveImagesToPdf(results, outputPath, quality);
|
PdfHelper.SaveImagesToPdf(results, outputPath);
|
||||||
|
|
||||||
// 清理
|
// 清理
|
||||||
foreach (Bitmap b in sourceImages) b.Dispose();
|
foreach (Bitmap b in sourceImages) b.Dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user