资源简介
C#语言,基于Twain、Wia两种操作扫描仪的方式,适合初学者了解扫描方法
代码片段和文件信息
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using TwainDotNet;
using TwainDotNet.WinFroms;
using TwainDotNet.TwainNative;
using WIA;
namespace TwainWia
{
public partial class FrmTwain : Form
{
private static AreaSettings AreaSettings = new AreaSettings(Units.Centimeters 0.1f 5.7f 0.1F + 2.6f 5.7f + 2.6f);
Twain _twain;
ScanSettings _settings;
public FrmTwain()
{
InitializeComponent();
_twain = new Twain(new WinFormsWindowMessageHook(this));
_twain.TransferImage += delegate(object sender TransferImageEventArgs args)
{
if (args.Image != null)
{
pictureBox1.Image = args.Image;
widthLabel.Text = “Width: “ + pictureBox1.Image.Width;
heightLabel.Text = “Height: “ + pictureBox1.Image.Height;
}
};
_twain.ScanningComplete += delegate
{
Enabled = true;
};
}
private void selectSource_Click(object sender EventArgs e)
{
_twain.SelectSource();
}
private void scan_Click(object sender EventArgs e)
{
Enabled = false;
_settings = new ScanSettings
{
UseDocumentFeeder = useAdfCheckBox.Checked
ShowTwainUI = useUICheckBox.Checked
ShowProgressIndicatorUI = showProgressIndicatorUICheckBox.Checked
UseDuplex = useDuplexCheckBox.Checked
Resolution =
blackAndWhiteCheckBox.Checked
? ResolutionSettings.Fax : ResolutionSettings.ColourPhotocopier
Area = !checkBoxArea.Checked ? null : AreaSettings
Rotation = new RotationSettings
{
AutomaticRotate = autoRotateCheckBox.Checked
AutomaticBorderDetection = autoDetectBorderCheckBox.Checked
}
};
try
{
_twain.StartScanning(_settings);
}
catch (TwainException ex)
{
MessageBox.Show(ex.Message);
Enabled = true;
}
}
private void saveButton_Click(object sender EventArgs e)
{
if (pictureBox1.Image != null)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image.Save(sfd.FileName);
}
}
}
private void diagnostics_Click(object sender EventArgs e)
{
var diagnostics = new Diagnostics(new WinFormsWindowMessageHook(this));
}
private void butto
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 143872 2018-07-26 16:50 TwainWia\.vs\TwainWia\v15\.suo
文件 4390 2018-07-26 16:49 TwainWia\TwainWia\FrmTwain.cs
文件 15852 2018-07-26 16:49 TwainWia\TwainWia\FrmTwain.designer.cs
文件 5814 2018-07-26 16:49 TwainWia\TwainWia\FrmTwain.resx
文件 138 2018-07-26 16:45 TwainWia\TwainWia\packages.config
文件 492 2018-07-26 16:34 TwainWia\TwainWia\Program.cs
文件 1314 2018-07-26 16:18 TwainWia\TwainWia\Properties\AssemblyInfo.cs
文件 2829 2018-07-26 16:18 TwainWia\TwainWia\Properties\Resources.Designer.cs
文件 5612 2018-07-26 16:18 TwainWia\TwainWia\Properties\Resources.resx
文件 1095 2018-07-26 16:18 TwainWia\TwainWia\Properties\Settings.Designer.cs
文件 249 2018-07-26 16:18 TwainWia\TwainWia\Properties\Settings.settings
文件 6562 2018-07-26 16:46 TwainWia\TwainWia\TwainWia.csproj
文件 1700 2018-07-26 16:37 TwainWia\TwainWia.sln
目录 0 2018-07-26 16:18 TwainWia\.vs\TwainWia\v15
目录 0 2018-07-26 16:18 TwainWia\.vs\TwainWia
目录 0 2018-07-26 16:18 TwainWia\TwainWia\Properties
...D.H. 0 2018-07-26 16:18 TwainWia\.vs
目录 0 2018-07-26 16:57 TwainWia\TwainWia
目录 0 2018-07-26 16:57 TwainWia
----------- --------- ---------- ----- ----
189919 19
- 上一篇:Skyline开发入门C#
- 下一篇:基于ASP.NET开发的学校美食网站
评论
共有 条评论