Access编程交流网
  • 设为首页|收藏本站|繁体中文|手机版
  •     
  • Access培训-Access开发平台-Access行业开发

  • 首页
  • 资讯
  • 技巧
  • 源码
  • 行业
  • 资源
  • 活动
  • 关于

技巧

ACCESS数据库

启动/设置/选项/背景

修复/压缩

安全/加密/解密

快捷键

版本升级/其它等

数据表

命名方式/设计规范

表设计

查询

Sql语言基础

选择查询

更新查询

删除查询

追加查询

生成表查询

交叉表查询

SQL特定查询

查询参数

查询综合应用

界面/窗体/控件

标签

文本框

命令按钮

组合框/列表框

选项组/复选框/选项按钮

选项卡

子窗体

窗体本身/综合应用

其它

报表打印

报表设计

高级报表

模块/函数/VBA/API/系统

VBA基础

内置函数

调试/跟踪/Debug

模块/类模块

API/COM/系统相关

字符数字日期

网络通信游戏

加密解密安全

文件处理

经典算法

宏/菜单/工具栏/功能区

宏/脚本

菜单/工具栏

功能区/Ribbon

图表/图形/图像/多媒体

图表

图形/图像

音频

视频/动画

DAO/链接表/ADO/ADP

DAO/链接表/ODBC

ADO/RDO

ADP

ActiveX/第三方控件/插件

Treeview树控件

ListView列表控件

Toolbar工具栏控件

微软其它控件

Dbi-Tech

CodeJock

Grid++Report

FastReport

ComponentOne

加载项/插件/Addin

OFFICE集成/导入导出/交互

Excel导入导出/交互

Word导入导出/交互

PPT交互

Outlook控制/邮件

Text文本文件/INI/CSV

PDF/SWF/XML格式

CAD格式

Sharepoint/其它Office

SqlServer/其它数据库

表

视图

存储过程/触发器

函数

用户/权限/安全

调试/维护

SqlServer其它/综合

发布/打包/文档/帮助

开发版/运行时

打包/发布/部署

开发文档/帮助制作

Access完整行业系统

采购管理系统

销售管理系统

仓库管理系统

人力资源管理HRM

CRM管理系统

MRP/ERP管理系统

BRP/流程优化

其它管理系统

心得/经验/绝招
其它/杂项
Excel技巧

Excel应用与操作

Excel开发编程

Word技巧

Word应用与操作

Word开发编程

Outlook技巧

Outlook应用与操作

Outlook开发编程

热门文章

  • Access在同一页面中调..
  • TWAIN驱动介绍-Acc..
  • Access VBA/VB..
  • TWAIN和WIA扫描仪的..
  • (转)在C#中使用WIA获..
  • 扫描程序设计说明文档(tw..

最新文章

  • Access 获取图片的像..
  • Access在同一页面中调..
  • 解决“我的电脑”中不显示扫..
  • WIA的脚本和NET(扫描..
  • 可用来连接扫描仪的国外第三..
  • 如何共享扫描仪

联系方式

Access交流网(免费Access交流)

QQ:18449932 

网  址:www.access-cn.com

当前位置:首页 > 技巧 > 图表/图形/图像/多媒体 > 图形/图像
图形/图像

可用来连接扫描仪的国外第三方免费控件Accessing TWAIN compatible scanner in Visual Basic

可用来连接扫描仪的国外第三方免费控件(此为免费版本,专业版本为收费),但对于Access来说,免费版也够用了

Accessing TWAIN compatible scanner in Visual Basic

PREFACE

http://lmik.sweb.cz/

This page describes the way VB programmers can use TWAIN scanners.

Developing some application I needed to access a scanner without showing the user interface that comes with a scanner driver. I have been searching the Internet to get some VB code concerning this topic but I found some DLLs or OCXs only (I must mention here a very handy dll called eztwain from www.dosadi.com). Finally I decided to dig into that problem by myself.

I have made a VB Module that can transfer one image at a time from scanner and save it as a file (BMP). There are three public functions in the module:

  • PopupSelectSourceDialog - shows TWAIN dialog for selecting default data source for acquisition

  • TransferWithoutUI - transfers one image from TWAIN data source without showing the data source user interface (silent transfer). The programmer can set following attributes of the image:The image is saved into the BMP file.

    • resolution (DPI)

    • colour depth - monochromatic, grey, fullcolour

    • image size and position on the scanner glass - left, top, right, bottom (in inches).

  • TransferWithUI - transfers one image from TWAIN data source using the data source user interface to set image attributes.
    The image is saved into the BMP file.

Functions return 0 if everything is OK, 1 if an error occurs.

ABOUT TWAIN

The way one can access an optical scanner is through a standard called TWAIN. If you want to get real knowledge about it I strongly recommend you to read the twain specification, located inwww.twain.org. If you just want to touch it briefly I can tell you that your application can communicate with the scanner using the DSM_Entry function located in the twain library.

To simply get one image one must:

  • open data source manager (twain dll)

  • open data source (scanner)

  • enable data source

  • transfer image from data source

  • disable data source

  • close data source

  • close data source manager.

Using different TWAIN triplets as the DSM_Entry function parameters, the programmer communicates with the data source manager or with the data source. 
For example a triplet DG_CONTROL DAT_PARENT MSG_OPENDSM opens data source manager, a triplet DG_CONTROL DAT_PARENT MSG_CLOSEDSM closes data source manager.

DECLARATION

First of all one must convert C declaration from twain.h into VB one. This is not much difficult if one has experienced it before. Declaration in twain.h says that TW_UINT32 is an unsigned longtype, TW_UINT16 is an unsigned short type, pTW_IDENTITY is a pointer to TW_IDENTITY structure and TW_MEMREF is a pointer to void.

Therefore

    TW_UINT16 FAR PASCAL DSM_Entry (pTW_IDENTITY pOrigin,
                                    pTW_IDENTITY pDest,
                                    TW_UINT32    DG,
                                    TW_UINT16    DAT,
                                    TW_UINT16    MSG,
                                    TW_MEMREF    pData);

is converted into:

    Private Declare Function DSM_Entry Lib "TWAIN_32.DLL" _
                                       (ByRef pOrigin As Any, _
                                        ByRef pDest As Any, _
                                        ByVal DG As Long, _
                                        ByVal DAT As Integer, _
                                        ByVal MSG As Integer, _
                                        ByRef pData As Any) As Integer

But there is a problem in converting some UDTs and it is called byte alignment. VB uses 4-byte alignment in UDT and adds so-called padding bytes to keep this kind of alignment. If Len of UDT differs from UDT's LenB you know there are some padding bytes in this UDT. Here in TWAIN, it is important to eliminate those padding bytes to get right values into right places (bytes) in UDT variables.

Example:

C declaration:

      typedef struct {
         TW_UINT16  ItemType;
         TW_UINT32  Item;
      } TW_ONEVALUE, FAR * pTW_ONEVALUE;

VB declaration:

      Private Type TW_ONEVALUE
          ItemType As Integer               ' TW_UINT16
          Item     As Long                  ' TW_UINT32
      End Type

Using this kind of declaration VB adds 2 padding bytes after the ItemType variable. So the size of TW_ONEVALUE becomes 8 bytes instead of 6 bytes. To eliminate padding bytes you may cut one Long type variable into two Integer ones:

      Private Type TW_ONEVALUE
          ItemType As Integer               ' TW_UINT16
          Item1    As Integer               ' TW_UINT32
          Item2    As Integer
      End Type

EXAMPLES OF USE

Finally there are some examples how to use this module in your code:

  1. Let us scan a greyscale image with 200 DPI and save it as noui_grey.bmp. We want to scan the whole scanner glass (set sngImageRight and sngImageBottom to 0) and we want to use silent transfer without showing the data source user interface:

        Dim lRtn As Long 
        
        lRtn = mdlTwain.TransferWithoutUI(200, GREY, 0, 0, 0, 0, _
                                          "noui_grey.bmp")
  2. Let us scan a monochromatic image with 300 DPI and save it as noui_mono.bmp. We want to scan the partial rectangle (left=1, top=1, right=2, bottom=5 inches) of the scanner glass and we want to use silent transfer without showing the data source user interface:

        Dim lRtn As Long 
        
        lRtn = mdlTwain.TransferWithoutUI(300, BW, 1, 1, 2, 5, _
                                          "noui_mono.bmp")
  3. Let us scan an image using the data source user interface to set its attributes and save it as ui.bmp:

        Dim lRtn As Long 
        
        lRtn = mdlTwain.TransferWithUI("ui.bmp")
  4. Let us choose the default data source (scanner) that will be used for next transfers:

        Dim lRtn As Long 
        
        lRtn = mdlTwain.PopupSelectSourceDialog()

UPDATES AND CHANGES

  • 2004/10/14 - Major changes. I have completely rebuilt the code and have numbered it as version 1.0.

    • As I left my first ideas about this code to be a class, I have changed it into VB module

    • Added option to transfer image with UI enabled - new public function TransferWithUI

    • Added option to select source - new public function PopupSelectSourceDialog

    • Added universal functions to set and get transfer and image attributes

    • Added some macros for converting data types

    • Added a lot of comments (hope useful)

  • 2004/03/30 - The new class version with corrected DMS_Entry function declaration.

DOWNLOAD AND CONTACT

The module can be downloaded here (version 1.0 - free to any use). 
I appreciate any feedback from you. It can be sent to LMik@seznam.cz.

Let me say a word of thanks to Alfred Koppold, who helped me with setting the scanner resolution and whose feedback helped me to understand the byte alignment problem.


发布人:zstmtony  
分享到:
点击次数:  更新时间:2017-02-06 22:34:46  【打印此页】  【关闭】
上一条:WIA的脚本和NET(扫描仪开发)  下一条:如何共享扫描仪



相关文章

  • • Access 获取图片的像素
  • • Access在同一页面中调用多张图片及放大图片
  • • 解决“我的电脑”中不显示扫描仪和摄像头
  • • WIA的脚本和NET(扫描仪开发)
  • • 如何共享扫描仪
  • • 扫描程序设计说明文档(twain_32调用说明)
  • • Delphi针对扫描仪编程开发的相关代码

热门文章

  • [2017-02-05] Delphi针对扫描仪编程开发的相关代码access数据库
  • [2014-12-19] 用代码插入图片到OLE对象的2种方法access数据库
  • [2017-08-28] Access 获取图片的像素access数据库
  • [2017-02-07] 解决“我的电脑”中不显示扫描仪和摄像头access数据库
  • [2017-02-05] TWAIN驱动介绍-Access使用扫描仪必学access数据库
  • [2017-02-07] WIA的脚本和NET(扫描仪开发)access数据库

热门产品

公司动态|在线留言|在线反馈|友情链接|会员中心|站内搜索|网站地图

中山市天鸣科技发展有限公司 版权所有 1999-2023 粤ICP备10043721号

QQ:18449932

Access应用 Access培训 Access开发 Access平台

access|数据库|access下载|access教程|access视频|access软件

Powered by MetInfo 5.3.12 ©2008-2025  www.metinfo.cn