C# 使用TWAIN协议进行扫描仪操作

C# 使用TWAIN协议进行扫描仪操作

 

折腾两台扫描仪程序的修改,今天有空把程序中涉及到扫描仪操作的代码贴出来,供大家一起交流学习。

复制代码
复制代码
 1 public ArrayList TransferPictures()
 2         {
 3             ArrayList pics = new ArrayList();
 4             if (srcds.Id == IntPtr.Zero)
 5                 return pics;
 6 
 7             TwRC rc;
 8             IntPtr hbitmap = IntPtr.Zero;
 9             TwPendingXfers pxfr = new TwPendingXfers();
10 
11             do
12             {
13                 pxfr.Count = 0;
14                 hbitmap = IntPtr.Zero;
15 
16                 TwImageInfo iinf = new TwImageInfo();//扫描仪设置的扫描图片信息
17 
18                 rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);//获取扫描图片信息
19                 if (rc != TwRC.Success)
20                 {
21                     CloseSrc();
22                     return pics;
23                 }
24 
25 
26                 rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);//扫描程序,如果扫描完成,则返回XferDone
27                 if (rc != TwRC.XferDone)
28                 {
29                     CloseSrc();
30                     return pics;
31                 }
32 
33 
34                 rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);//结束扫描
35                 if (rc != TwRC.Success)
36                 {
37                     CloseSrc();
38                     return pics;
39                 }
40 
41                 pics.Add(hbitmap);
42             }
43             while (pxfr.Count != 0);
44 
45             rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);
46             return pics;
47         }
复制代码
复制代码
作者:Peter Luo
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

posted on   漫思  阅读(8)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
历史上的今天:
2023-12-31 优雅的设计
2023-12-31 BBC 开源的声音可视化库
2019-12-31 React.Children的使用
2019-12-31 如何更改账户信息

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示