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();