TWAIN機器からの入力 <TOP>
TWAIN対応機器からの入力と、その画像を描画します。
EZTW32.DLLというフリーソフトを見つけました。
http://www.geocities.com/smigman.geo/mci/home.html
http://www.nodevice.com/dll/EZTW32_DLL/item6371.html
イメージスキャナ、Webカメラなどを操作できそうです。
TWAIN_SelectImageSource TWAIN機器の選択
TWAIN_AcquireToClipboard TWAIN機器から取得したデータをクリップボードへ転送
TWAIN_AcquireToFilename TWAIN機器から取得したデータをファイル保存
「TWAIN選択」:TWAIN対応機器を選択します。
「Image取得」:読み取ったデータをクリップボードに転送します。
「取得保存」:読み取ったデータをBitmap型式ファイルで保存します。
「描画」:一旦保存したファイルを読み出して描画させています。
'================================================================ '= TWAIN機器からの入力
'= (Twain.bas) '================================================================ #include "Windows.bi" ' TWAIN機器の選択 Declare Function TWAIN_SelectImageSource& Lib "Eztw32" Alias "TWAIN_SelectImageSource" (ByVal hWnd&) ' TWAIN機器から取得したデータをクリップボードへ転送 Declare Function TWAIN_AcquireToClipboard& Lib "Eztw32" Alias "TWAIN_AcquireToClipboard" (ByVal hwndApp&, ByVal wPixTypes&) ' TWAIN機器から取得したデータをファイル保存 Declare Function TWAIN_AcquireToFilename& Lib "Eztw32" Alias "TWAIN_AcquireToFilename" (ByVal hwndApp&, ByVal sFile$) #define CF_BITMAP 2 'ビットマップのデータ(HBITMAP) #define CF_DIB 8 '構造体とビットマップビットからなるメモリオブジェクト #define CF_METAFILEPICT 3 'メタファイル画像形式。METAFILEPICT構造体のメモリオブジェクト #define CF_TEXT 1 'テキスト形式のデータ。各行は復帰改行(CR-LF)コードで終わる Var Shared Picture1 As Object Var Shared Edit1 As Object Var Shared Button(3) As Object Var Shared Radio1 As Object Var Shared Radio2 As Object Var Shared Bitmap1 As Object BitmapObject Bitmap1 Picture1.Attach GetDlgItem("Picture1") Edit1.Attach getDlgItem("Edit1") : Edit1.SetFontSize 14 Radio1.Attach getDlgItem("Radio1") : Radio1.SetFontSize 14 Radio2.Attach getDlgItem("Radio2") : Radio2.SetFontSize 14 For i = 0 To 3 Button(i).Attach GetDlgItem("Button" & Trim$(Str$(i + 1))) Button(i).SetFontSize 14 Next Var Shared FileName As String '================================================================ '= '================================================================ Declare Function Flg bdecl () As Integer Function Flg() Flg = Val(Mid$(GetDlgRadioSelect("Radio1"), 6)) -1 End Function '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() ShowWindow -1 End Sub '================================================================ '= TWAIN機器の選択 '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Ret As Long Ret = TWAIN_SelectImageSource(GethWnd) End Sub '================================================================ '= スキャンしクリップボードへ転送 '================================================================ Declare Sub Button2_on edecl () Sub Button2_on() Var Ret As Long Picture1.Cls ClearCB Ret = TWAIN_AcquireToClipboard(GethWnd, 0) If Ret = 0 Then A% = MessageBox(GetWindowText, "イメージの取得・クリップボードへの転送は失敗しました!", 0, 2) Exit Sub End If End Sub '================================================================ '= スキャンし取得データをファイルに保存 '================================================================ Declare Sub Button3_on edecl () Sub Button3_on() Var Ret As Long FileName = Edit1.GetWindowText Ret = TWAIN_AcquireToFilename(GethWnd, FileName) End Sub '================================================================ '= ファイルを読み込みピクチャボックスに描画 '================================================================ Declare Sub Button4_on edecl () Sub Button4_on() Picture1.Cls On Error Goto *ErrTrap Bitmap1.LoadFile Edit1.GetWindowText If Flg = 0 Then Picture1.DrawBitmap Bitmap1, 0, 0 Else Picture1.StretchBitmap Bitmap1, 0, 0, Picture1.GetWidth, Picture1.GetHeight End If Bitmap1.DeleteBitmap *ErrRet On Error Goto 0 Exit Sub *ErrTrap A% = MessageBox(GetWindowText, "ファイルが見あたりません!", 0, 2) Resume *ErrRet End Sub '================================================================ '= '================================================================ Declare Sub MainForm_Resize edecl () Sub MainForm_Resize() If GetWidth < 350 Or GetHeight < 354 Then SetWindowSize 350, 354 End If Picture1.SetWindowSize GetWidth - 30, GetHeight - 110 Edit1.MoveWindow 176, GetHeight - 96 Radio1.MoveWindow 6, GetHeight - 94 Radio2.MoveWindow 94, GetHeight - 94 Button(0).MoveWindow 12, GetHeight - 68 Button(1).MoveWindow 92, GetHeight - 68 Button(2).MoveWindow 172, GetHeight - 68 Button(3).MoveWindow 252, GetHeight - 68 End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End
参考
Declare
Function TWAIN_AbortAllPendingXfers& Lib "Eztw32" Alias
"TWAIN_AbortAllPendingXfers" ()
Declare Function TWAIN_AcquireNative& Lib "Eztw32" Alias "TWAIN_AcquireNative"
(ByVal hwndApp&, ByVal wPixTypes&)
Declare Function TWAIN_AcquireToClipboard& Lib "Eztw32" Alias
"TWAIN_AcquireToClipboard" (ByVal hwndApp&, ByVal wPixTypes&)
Declare Function TWAIN_AcquireToFilename& Lib "Eztw32" Alias
"TWAIN_AcquireToFilename" (ByVal hwndApp&, ByVal sFile$)
Declare Function TWAIN_CloseSource& Lib "Eztw32" Alias "TWAIN_CloseSource" ()
Declare Function TWAIN_CloseSourceManager& Lib "Eztw32" Alias
"TWAIN_CloseSourceManager" (ByVal hWnd&)
Declare Function TWAIN_CreateDibPalette& Lib "Eztw32" Alias
"TWAIN_CreateDibPalette" (ByVal hDib&)
Declare Function TWAIN_DibDepth& Lib "Eztw32" Alias "TWAIN_DibDepth" (ByVal
hDib&)
Declare Function TWAIN_DibHeight& Lib "Eztw32" Alias "TWAIN_DibHeight" (ByVal
hDib&)
Declare Function TWAIN_DibNumColors& Lib "Eztw32" Alias "TWAIN_DibNumColors"
(ByVal hDib&)
Declare Function TWAIN_DibWidth& Lib "Eztw32" Alias "TWAIN_DibWidth" (ByVal
hDib&)
Declare Function TWAIN_DisableSource& Lib "Eztw32" Alias "TWAIN_DisableSource"
()
Declare Function TWAIN_EasyVersion& Lib "Eztw32" Alias "TWAIN_EasyVersion" ()
Declare Function TWAIN_EnableSource& Lib "Eztw32" Alias "TWAIN_EnableSource"
(ByVal hWnd&)
Declare Function TWAIN_EndXfer& Lib "Eztw32" Alias "TWAIN_EndXfer" ()
Declare Function TWAIN_GetBitDepth& Lib "Eztw32" Alias "TWAIN_GetBitDepth" ()
Declare Function TWAIN_GetConditionCode& Lib "Eztw32" Alias
"TWAIN_GetConditionCode" ()
Declare Function TWAIN_GetCurrentResolution# Lib "Eztw32" Alias
"TWAIN_GetCurrentResolution" ()
Declare Function TWAIN_GetCurrentUnits& Lib "Eztw32" Alias
"TWAIN_GetCurrentUnits" ()
Declare Function TWAIN_GetHideUI& Lib "Eztw32" Alias "TWAIN_GetHideUI" ()
Declare Function TWAIN_GetPixelType& Lib "Eztw32" Alias "TWAIN_GetPixelType" ()
Declare Function TWAIN_GetResultCode& Lib "Eztw32" Alias "TWAIN_GetResultCode"
()
Declare Function TWAIN_IsAvailable& Lib "Eztw32" Alias "TWAIN_IsAvailable" ()
Declare Function TWAIN_LoadNativeFromFile& Lib "Eztw32" Alias
"TWAIN_LoadNativeFromFile" (ByVal hFile&)
Declare Function TWAIN_LoadNativeFromFilename& Lib "Eztw32" Alias
"TWAIN_LoadNativeFromFilename" (ByVal sFile$)
Declare Function TWAIN_LoadSourceManager& Lib "Eztw32" Alias
"TWAIN_LoadSourceManager" ()
Declare Function TWAIN_MessageHook& Lib "Eztw32" Alias "TWAIN_MessageHook"
(lpMsg As Any)
Declare Function TWAIN_NegotiatePixelTypes& Lib "Eztw32" Alias
"TWAIN_NegotiatePixelTypes" (ByVal wPixTypes&)
Declare Function TWAIN_NegotiateXferCount& Lib "Eztw32" Alias
"TWAIN_NegotiateXferCount" (ByVal nXfers&)
Declare Function TWAIN_OpenDefaultSource& Lib "Eztw32" Alias
"TWAIN_OpenDefaultSource" ()
Declare Function TWAIN_OpenSourceManager& Lib "Eztw32" Alias
"TWAIN_OpenSourceManager" (ByVal hWnd&)
Declare Function TWAIN_RowSize& Lib "Eztw32" Alias "TWAIN_RowSize" (ByVal hDib&)
Declare Function TWAIN_SelectImageSource& Lib "Eztw32" Alias
"TWAIN_SelectImageSource" (ByVal hWnd&)
Declare Function TWAIN_SetBitDepth& Lib "Eztw32" Alias "TWAIN_SetBitDepth"
(ByVal nBits&)
Declare Function TWAIN_SetBrightness& Lib "Eztw32" Alias "TWAIN_SetBrightness"
(ByVal dBri#)
Declare Function TWAIN_SetContrast& Lib "Eztw32" Alias "TWAIN_SetContrast"
(ByVal dCon#)
Declare Function TWAIN_SetCurrentPixelType& Lib "Eztw32" Alias
"TWAIN_SetCurrentPixelType" (ByVal nPixType&)
Declare Function TWAIN_SetCurrentResolution& Lib "Eztw32" Alias
"TWAIN_SetCurrentResolution" (ByVal dRes#)
Declare Function TWAIN_SetCurrentUnits& Lib "Eztw32" Alias
"TWAIN_SetCurrentUnits" (ByVal nUnits&)
Declare Function TWAIN_State& Lib "Eztw32" Alias "TWAIN_State" ()
Declare Function TWAIN_UnloadSourceManager& Lib "Eztw32" Alias
"TWAIN_UnloadSourceManager" ()
Declare Function TWAIN_WaitForNativeXfer& Lib "Eztw32" Alias
"TWAIN_WaitForNativeXfer" (ByVal hWnd&)
Declare Function TWAIN_WriteDibToFile& Lib "Eztw32" Alias "TWAIN_WriteDibToFile"
(ByVal lpDib&, ByVal hFile&)
Declare Function TWAIN_WriteNativeToFile& Lib "Eztw32" Alias
"TWAIN_WriteNativeToFile" (ByVal hDib&, ByVal hFile&)
Declare Function TWAIN_WriteNativeToFilename& Lib "Eztw32" Alias
"TWAIN_WriteNativeToFilename" (ByVal hDib&, ByVal sFile$)
Declare Sub TWAIN_DrawDibToDC Lib "Eztw32" Alias "TWAIN_DrawDibToDC" (ByVal
hDC&, ByVal nDestX&, ByVal nDestX&, ByVal nWidth&, ByVal nHeight&, ByVal hDib&,
ByVal nSrcX&, ByVal nSrcX&)
Declare Sub TWAIN_ErrorBox Lib "Eztw32" Alias "TWAIN_ErrorBox" (ByVal sMsg$)
Declare Sub TWAIN_FreeNative Lib "Eztw32" Alias "TWAIN_FreeNative" (ByVal hDib&)
Declare Sub TWAIN_ModalEventLoop Lib "Eztw32" Alias "TWAIN_ModalEventLoop" ()
Declare Sub TWAIN_ReadRow Lib "Eztw32" Alias "TWAIN_ReadRow" (ByVal hDib&, ByVal
nRow&, prow As Any)
Declare Sub TWAIN_RegisterApp Lib "Eztw32" Alias "TWAIN_RegisterApp" (ByVal
nMajorNum&, ByVal nMinorNum&, ByVal nLanguage&, ByVal nCountry&, ByVal
sVersion$, ByVal sMfg$, ByVal sFamily$, ByVal sProduct$)
Declare Sub TWAIN_ReportLastError Lib "Eztw32" Alias "TWAIN_ReportLastError"
(ByVal sMsg$)
Declare Sub TWAIN_SetHideUI Lib "Eztw32" Alias "TWAIN_SetHideUI" (ByVal nHide&)