C# 调整扫描仪设置后,扫描仪变慢
首先,如果我不通过wia调整扫描仪设置(dpi、宽度、高度、颜色),我可以达到全速。但是,我可以使用“窗口传真和扫描”应用程序全速运行,甚至可以调整扫描仪设置。C# 调整扫描仪设置后,扫描仪变慢,c#,epson,wia,C#,Epson,Wia,首先,如果我不通过wia调整扫描仪设置(dpi、宽度、高度、颜色),我可以达到全速。但是,我可以使用“窗口传真和扫描”应用程序全速运行,甚至可以调整扫描仪设置。 显然我的代码有问题。我正在使用jeske()中的库 现在,我可以连接到我的扫描仪(爱普生ds-780N)并通过自动文档进纸器成功扫描。噩梦是,从扫描仪传输数据(ShowTransfer函数)将花费我5秒的时间。这台扫描仪每分钟可以扫描45页,但我只能扫描10页 public static List<PendingF
显然我的代码有问题。我正在使用jeske()中的库 现在,我可以连接到我的扫描仪(爱普生ds-780N)并通过自动文档进纸器成功扫描。噩梦是,从扫描仪传输数据(ShowTransfer函数)将花费我5秒的时间。这台扫描仪每分钟可以扫描45页,但我只能扫描10页
public static List<PendingFile> Scan(string scannerId, WIAScanQuality quality, WIAPageSize pageSize,string category)
{
List<PendingFile> results = new List<PendingFile>();
bool hasMorePages = true;
int numbrPages = 0;
WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
// connect the correct scanner using the provided scannerId parameter
var device = connect(scannerId);
WIA.Item item = device.Items[1] as WIA.Item;
int dpi = 100;
int width_pixels = (int)(8.3f * dpi);
int height_pixels = (int)(11.7f * dpi);
// if i call this function , scanner will become very slow.
AdjustScannerSettings(item, dpi, 0, 0, width_pixels, height_pixels, 0, 0, 1);
do
{
PendingFile fileInfo = genPendingInfo(category);
try
{
// scan image
WIA.ImageFile image = item.Transfer(wiaFormatJPEG);
//WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatJPEG, false);
// save to temp file
Byte[] imageBytes = (byte[])image.FileData.get_BinaryData(); // <– Converts the ImageFile to a byte array
MemoryStream ms = new MemoryStream(imageBytes);
Image img = Image.FromStream(ms);
string fileName = Utils.genFileName(fileInfo);
using (EncoderParameters encoderParameters = new EncoderParameters(1))
using (EncoderParameter encoderParameter = new EncoderParameter(Encoder.Quality, 90L))
{
ImageCodecInfo codecInfo = ImageCodecInfo.GetImageDecoders().First(codec => codec.FormatID == ImageFormat.Jpeg.Guid);
encoderParameters.Param[0] = encoderParameter;
img.Save(fileName, codecInfo, encoderParameters);
img.Dispose();
}
Image temp = Image.FromFile(fileName);
Image thumb = temp.GetThumbnailImage(126, 180, () => false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(fileName, ".thumbnail.jpg"));
thumb.Dispose();
image = null;
// add file to output list
results.Add(fileInfo);
temp.Dispose();
numbrPages++;
}
catch (System.Runtime.InteropServices.COMException ex)
{
switch ((uint)ex.ErrorCode)
{
case WIA_ERRORS.WIA_ERROR_PAPER_EMPTY:
hasMorePages = false;
break;
case WIA_ERRORS.WIA_ERROR_PAPER_JAM:
MessageBox.Show("Paper jam inside the scanner feeder");
hasMorePages = false;
break;
default:
throw ex;
}
}
} while (hasMorePages);
device = null;
return results;
}
private static void SetWIAProperty(WIA.IProperties properties,
object propName, object propValue)
{
WIA.Property prop = properties.get_Item(ref propName);
prop.set_Value(ref propValue);
}
private static void AdjustScannerSettings(IItem scannnerItem, int scanResolutionDPI, int scanStartLeftPixel, int scanStartTopPixel,
int scanWidthPixels, int scanHeightPixels, int brightnessPercents, int contrastPercents, int colorMode )
{
const string WIA_SCAN_COLOR_MODE = "6146";
const string WIA_HORIZONTAL_SCAN_RESOLUTION_DPI = "6147";
const string WIA_VERTICAL_SCAN_RESOLUTION_DPI = "6148";
const string WIA_HORIZONTAL_SCAN_START_PIXEL = "6149";
const string WIA_VERTICAL_SCAN_START_PIXEL = "6150";
const string WIA_HORIZONTAL_SCAN_SIZE_PIXELS = "6151";
const string WIA_VERTICAL_SCAN_SIZE_PIXELS = "6152";
const string WIA_SCAN_BRIGHTNESS_PERCENTS = "6154";
const string WIA_SCAN_CONTRAST_PERCENTS = "6155";
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_RESOLUTION_DPI, scanResolutionDPI);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_RESOLUTION_DPI, scanResolutionDPI);
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_START_PIXEL, scanStartLeftPixel);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_START_PIXEL, scanStartTopPixel);
SetWIAProperty(scannnerItem.Properties, WIA_HORIZONTAL_SCAN_SIZE_PIXELS, scanWidthPixels);
SetWIAProperty(scannnerItem.Properties, WIA_VERTICAL_SCAN_SIZE_PIXELS, scanHeightPixels);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_BRIGHTNESS_PERCENTS, brightnessPercents);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_CONTRAST_PERCENTS, contrastPercents);
SetWIAProperty(scannnerItem.Properties, WIA_SCAN_COLOR_MODE, colorMode);
}
公共静态列表扫描(字符串扫描ID、WIAScanQuality质量、WIAPageSize页面大小、字符串类别)
{
列表结果=新列表();
bool hasMorePages=true;
int numberpage=0;
WIA.ICommonDialog wiaCommonDialog=新建WIA.CommonDialog();
//使用提供的scannerId参数连接正确的扫描仪
var设备=连接(扫描仪ID);
WIA.Item=device.Items[1]作为WIA.Item;
int-dpi=100;
int-width_像素=(int)(8.3f*dpi);
int高度_像素=(int)(11.7f*dpi);
//如果我调用此函数,扫描仪将变得非常慢。
调整扫描设置(项目、dpi、0、0、宽度像素、高度像素、0、0、1);
做
{
PendingFile fileInfo=genPendingInfo(类别);
尝试
{
//扫描图像
WIA.ImageFile image=item.Transfer(wiaFormatJPEG);
//WIA.ImageFile image=(WIA.ImageFile)wiaCommonDialog.ShowTransfer(项,wiaFormatJPEG,false);
//保存到临时文件
Byte[]imageBytes=(Byte[])image.FileData.get_BinaryData();//codec.FormatID==ImageFormat.Jpeg.Guid);
encoderParameters.Param[0]=encoderParameter;
保存(文件名、编码信息、编码参数);
img.Dispose();
}
Image temp=Image.FromFile(文件名);
Image thumb=temp.GetThumbnailImage(126180,()=>false,IntPtr.Zero);
Save(Path.ChangeExtension(文件名“.thumb.jpg”);
thumb.Dispose();
image=null;
//将文件添加到输出列表
结果.添加(fileInfo);
temp.Dispose();
numbrPages++;
}
捕获(System.Runtime.InteropServices.COMException ex)
{
开关((uint)ex.ErrorCode)
{
案例WIA_错误。WIA_错误\u纸张\u空:
hasMorePages=false;
打破
案例WIA_错误。WIA_错误\u卡纸:
MessageBox.Show(“扫描仪进纸器内卡纸”);
hasMorePages=false;
打破
违约:
掷骰子;
}
}
}while(hasMorePages);
设备=空;
返回结果;
}
私有静态void SetWIAProperty(WIA.iproperty属性,
对象propName、对象propValue)
{
WIA.Property prop=properties.get_项(ref propName);
属性设置值(参考属性值);
}
专用静态空隙调整扫描设置(IItem SCANNERITEM、int scanResolutionDPI、int SCANSTARTEFTPIXEL、int SCANSTARTOPPIXEL、,
int扫描宽度像素、int扫描高度像素、int亮度百分比、int对比度百分比、int颜色模式)
{
常量字符串WIA_扫描_颜色_模式=“6146”;
常量字符串WIA_水平扫描分辨率_DPI=“6147”;
常量字符串WIA_垂直扫描_分辨率_DPI=“6148”;
常量字符串WIA\u水平扫描\u开始\u像素=“6149”;
常量字符串WIA\u垂直扫描\u开始\u像素=“6150”;
常量字符串WIA_水平扫描_大小_像素=“6151”;
常量字符串WIA_垂直_扫描_大小_像素=“6152”;
常量字符串WIA_扫描_亮度_百分比=“6154”;
常量字符串WIA_扫描_对比度_PERCENTS=“6155”;
设置WIA属性(扫描属性、WIA\u水平扫描分辨率\u DPI、扫描分辨率DPI);
SETWIA属性(扫描属性、垂直扫描分辨率DPI、扫描分辨率DPI);
设置WIA属性(扫描属性、WIA_水平扫描_开始像素、扫描起始像素);
SetWIAProperty(扫描属性、垂直扫描像素、扫描起始像素);
SetWIAProperty(ScannerItem.Properties、WIA_水平_扫描_大小_像素、scanWidthPixels);
SetWIAProperty(扫描属性、垂直扫描大小像素、扫描高度像素);
设置WIA属性(扫描属性、WIA_扫描亮度百分比、亮度百分比);
设置WIA属性(扫描属性、WIA\u扫描对比度、对比度百分比);
设置WIA属性(扫描属性、WIA\u扫描颜色模式、颜色模式);
}
为了帮助您,我们需要查看您的实际代码,而不是