C#WIA图像扫描失败,出现HRESULT:0x80070050 [英] C# WIA Image Scanning fails with HRESULT: 0x80070050

查看:150
本文介绍了C#WIA图像扫描失败,出现HRESULT:0x80070050的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人遇到过-我正在尝试使用WIA从文档扫描仪捕获图像,但是在尝试传输图像结果的随机计算机上-WIA报告文件存在.-HRESULT:0x80070050 )".在所有出现此问题的计算机上,该软件的初次使用均成功.

I'm hoping someone has come across this - I'm trying to capture images from a document scanner using WIA, however on random machines when attempting to transfer the image result - WIA reports "The file exists. - HRESULT: 0x80070050)". On All machines with this issue, initial use of the software was successful.

我能够成功连接到扫描仪,查询名称,制造商等.

I am able to connect successfully to the scanner, query for Name, Manufacturer,etc.

如果我以其他用户帐户运行代码(使用以管理员身份右键单击运行),则我确定可以成功扫描图像.但是,在具有特权提升的同一用户帐户下运行代码会导致相同的错误.

I've determined that i can successfully scan an image, if i run the code under an alternative user account (Using right-click run as administrator). However, running the code under the same user account with elevated privledges results in the same error.

注意:Item1.Transfer发生异常-到目前为止,我还没有为WIA提供文件路径,因此该文件不能是它所引用的文件.

NOTE: Exception is happening on Item1.Transfer - so up until this point i haven't yet provided WIA with a file path, so this can't be the file it's referring to.

WIA.DeviceManager DeviceManager1 = new WIA.DeviceManagerClass();
WIA.Device Scanner = DeviceManager1.DeviceInfos[i].Connect();

WIA.Item Item1 = null;
foreach (WIA.Item CurrentItem in Scanner.Items) {
    Item1 = CurrentItem;
    break;
}

WIA.ImageFile Image1 = new WIA.ImageFile();

//Attempt To Capture Scan
Image1 = (WIA.ImageFile)Item1.Transfer(WIA.FormatID.wiaFormatJPEG);

//Save To File
Image1.SaveFile(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + @"\scan" + DateTime.Now.Ticks + ".jpg");

最合乎逻辑的答案是,WIA在图像捕获期间存储了一个临时文件-我不知道-该文件无法覆盖以前的扫描.有人知道这可能在哪里吗?

The most logical answer is that WIA is storing a temporary file during image capture - that i'm not aware of - and it is unable to overwrite a previous scan. Does anyone know where this might be?

推荐答案

已解决.

事实证明,WIA实际上将捕获的图像作为临时文件存储在用户"配置文件的temp文件夹中,因此:

It turns out that WIA actually stores captured images as temporary files in the Users profile temp folder, so:

Path.GetTempPath()

或C:\ Users \ USER_PROFILE \ AppData \ Local \ Temp \

or C:\Users\USER_PROFILE\AppData\Local\Temp\

文件以imgXXXX.tmp格式存储

Files are stored in the format imgXXXX.tmp

在我们的案例中-导致出现问题的原因(似乎在网络上的任何地方都没有记录)是因为我们每隔几秒钟就对扫描仪进行一次轮询-创建一个临时文件,因为只有4x,所以可以在WIA发生错误之前,最多可容纳65K个临时文件.

In our case - the reason this caused an issue, which doesn't seem to be documented anywhere on the net, is that we polled the scanner every few seconds - creating a temp file, as there are only 4x's, there can be a max of 65K temp files before WIA will bug out.

设置例程以清除此temp文件夹中的旧图像文件,立即解决了该问题.

Setting up a routine to clear out old image files from this temp folder immediately resolved the issue.

这篇关于C#WIA图像扫描失败,出现HRESULT:0x80070050的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆