From 9a7a367a4fdf7a7b2e65fbe1c70f91d4d0c30ccf Mon Sep 17 00:00:00 2001 From: sinvo Date: Thu, 19 Mar 2026 23:50:12 +0800 Subject: [PATCH] =?UTF-8?q?UI=E4=BC=98=E5=8C=96=EF=BC=9A=E6=94=B9=E5=90=8D?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=89=AB=E6=8F=8F=E7=8E=8B=E3=80=81=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=B4=A8=E9=87=8F=E9=80=89=E9=A1=B9=E3=80=81=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E6=94=BE=E5=A4=A7=E3=80=81=E6=99=BA=E8=83=BD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 软件名称改为"文档扫描王" - 去掉JPEG质量选项,改用PNG无损写入PDF - 预览区域从685x190放大到710x440 - 窗口高度从600增到820 - 输出文件名:图片输入→时间戳.pdf,PDF输入→modify_原名.pdf - 删除GetJpegCodec等不再需要的代码 Co-Authored-By: Claude Opus 4.6 --- CamScanner.cs | 93 +++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 59 deletions(-) diff --git a/CamScanner.cs b/CamScanner.cs index 5e95797..ace65b4 100644 --- a/CamScanner.cs +++ b/CamScanner.cs @@ -548,7 +548,7 @@ public static class PdfHelper /// /// 将多张图像保存为单个PDF /// - public static void SaveImagesToPdf(List images, string outputPath, int jpegQuality) + public static void SaveImagesToPdf(List images, string outputPath) { Document doc = null; PdfWriter writer = null; @@ -573,11 +573,7 @@ public static class PdfHelper byte[] imgBytes; using (MemoryStream ms = new MemoryStream()) { - EncoderParameters ep = new EncoderParameters(1); - ep.Param[0] = new EncoderParameter( - System.Drawing.Imaging.Encoder.Quality, (long)jpegQuality); - ImageCodecInfo codec = GetJpegCodec(); - bmp.Save(ms, codec, ep); + bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); 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; - } } /// @@ -614,7 +601,6 @@ public class ScannerForm : Form private ListBox lstFiles; private Button btnAddImages, btnAddPdf, btnRemove, btnClear; private Button btnMoveUp, btnMoveDown, btnProcess; - private NumericUpDown nudQuality; private ProgressBar progressBar; private Label lblStatus; private PictureBox picPreview; @@ -629,8 +615,8 @@ public class ScannerForm : Form private void InitUI() { - this.Text = "文档扫描增强工具 v2"; - this.Size = new System.Drawing.Size(720, 600); + this.Text = "文档扫描王"; + this.Size = new System.Drawing.Size(750, 820); this.StartPosition = FormStartPosition.CenterScreen; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; @@ -731,47 +717,26 @@ public class ScannerForm : Form }; this.Controls.Add(btnMoveDown); - // JPEG质量 - GroupBox grp = new GroupBox(); - grp.Text = "输出设置"; - grp.Location = new System.Drawing.Point(15, 222); - grp.Size = new System.Drawing.Size(685, 55); - grp.Font = new System.Drawing.Font("微软雅黑", 9f); - this.Controls.Add(grp); + // 提示 + Label lblHint = new Label(); + lblHint.Text = "(自动执行:透视矫正 → 倾斜校正 → 增强美化,一步到位)"; + lblHint.Location = new System.Drawing.Point(15, 225); + lblHint.AutoSize = true; + lblHint.ForeColor = System.Drawing.Color.FromArgb(100, 100, 100); + 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(); lblPrev.Text = "预览:"; - lblPrev.Location = new System.Drawing.Point(15, 285); + lblPrev.Location = new System.Drawing.Point(15, 248); lblPrev.AutoSize = true; lblPrev.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Bold); this.Controls.Add(lblPrev); picPreview = new PictureBox(); - picPreview.Location = new System.Drawing.Point(15, 308); - picPreview.Size = new System.Drawing.Size(685, 190); + picPreview.Location = new System.Drawing.Point(15, 270); + picPreview.Size = new System.Drawing.Size(710, 440); picPreview.SizeMode = PictureBoxSizeMode.Zoom; picPreview.BorderStyle = BorderStyle.FixedSingle; picPreview.BackColor = System.Drawing.Color.White; @@ -779,20 +744,20 @@ public class ScannerForm : Form // 底部 progressBar = new ProgressBar(); - progressBar.Location = new System.Drawing.Point(15, 510); - progressBar.Size = new System.Drawing.Size(480, 25); + progressBar.Location = new System.Drawing.Point(15, 722); + progressBar.Size = new System.Drawing.Size(510, 25); this.Controls.Add(progressBar); lblStatus = new Label(); lblStatus.Text = "就绪 - 添加文件后点击处理"; - lblStatus.Location = new System.Drawing.Point(15, 538); - lblStatus.Size = new System.Drawing.Size(480, 20); + lblStatus.Location = new System.Drawing.Point(15, 752); + lblStatus.Size = new System.Drawing.Size(510, 20); lblStatus.ForeColor = System.Drawing.Color.DarkGray; this.Controls.Add(lblStatus); btnProcess = new Button(); 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.Font = new System.Drawing.Font("微软雅黑", 10f, System.Drawing.FontStyle.Bold); btnProcess.BackColor = System.Drawing.Color.FromArgb(0, 120, 215); @@ -867,14 +832,24 @@ public class ScannerForm : Form return; } + // 默认输出文件名 + string defaultName; + if (isPdfInput) + { + defaultName = "modify_" + Path.GetFileName(inputFiles[0]); + } + else + { + defaultName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"; + } + SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "保存处理后的PDF"; sfd.Filter = "PDF|*.pdf"; - sfd.FileName = "scanned_output.pdf"; + sfd.FileName = defaultName; if (sfd.ShowDialog() != DialogResult.OK) return; string outputPath = sfd.FileName; - int quality = (int)nudQuality.Value; SetUI(false); try @@ -927,7 +902,7 @@ public class ScannerForm : Form // 生成PDF lblStatus.Text = "正在生成PDF..."; Application.DoEvents(); - PdfHelper.SaveImagesToPdf(results, outputPath, quality); + PdfHelper.SaveImagesToPdf(results, outputPath); // 清理 foreach (Bitmap b in sourceImages) b.Dispose();