【发布时间】:2020-01-26 13:21:45
【问题描述】:
我想扫描页面并自动保存。此代码运行良好,但问题是创建然后保存的图像太大!它会创建一个大小为 30Mb 的图像!
如何更改此代码以保存正常大小的图像?
这是我的代码:
谢谢。
private void button7_Click(object sender, EventArgs e)
{
try
{
var deviceManager = new DeviceManager();
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
lstListOfScanner.Items.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
}
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
try
{
var deviceManager = new DeviceManager();
DeviceInfo AvailableScanner = null;
for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
{
if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
{
continue;
}
AvailableScanner = deviceManager.DeviceInfos[i];
break;
}
var device = AvailableScanner.Connect(); //Connect to the available scanner.
var ScanerItem = device.Items[1]; // select the scanner.
var imgFile = (ImageFile)ScanerItem.Transfer(FormatID.wiaFormatJPEG); //Retrive an image in Jpg format and store it into a variable.
var Path = @"C:\....\ScanImg.jpg"; // save the image in some path with filename.
if (File.Exists(Path))
{
File.Delete(Path);
}
imgFile.SaveFile(Path);
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
/////////////////////////////////////
}
【问题讨论】:
-
我不知道如何将该代码添加到我的代码中。可以请你添加它吗?
-
好的,在使用How to resize an Image C#之前需要从ImageFile对象中获取一个Image对象。什么是 ScanerItem 程序集参考?
-
好的,谢谢。如果您可以连接这两个代码,那就太好了:)我使用的是 WIA;使用 System.Runtime.InteropServices;使用 System.Drawing;使用 System.IO;使用系统;
-
看答案。
标签: c# image-resizing scanning image-size save-image