Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WANG scan control

Posted on 1999-07-12
4
Medium Priority
?
543 Views
Last Modified: 2012-05-04
Could anyone explain the pros and cons of the WANG Image Scan control and if it is worth adding to my application.  I considered using this control in my app.  I would like to use the TWAIN interface because I heard it was better but I have never used it.  Part of my app requires me to scan and save images.  Also, if someone shows me how to use the TWAIN interface (with code), I will add 400 points to this question.  This is not necessary though.
0
Comment
Question by:NeedAnswer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
4 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1524129
' 32-bit EZTWAIN functions for Visual Basic 5.0
Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp&, ByVal wPixTypes&) As Long
Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp&) As Long

'On Form1
'Add Picture1
'Add Command1 and Command2
'Add following code
Private Sub Command1_Click()
r = TWAIN_SelectImageSource(Me.hWnd)
End Sub

Private Sub Command2_Click()
r = TWAIN_AcquireToClipboard(Me.hWnd, t%)
Picture1.Picture = Clipboard.GetData(vbCFDIB)

End Sub
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 400 total points
ID: 1524130
You can do this with the freeware eztw32.dll. I can't remember where I got it, so you can download it from

http://pages.hotbot.com/sf/nyx/images/Eztw32.dll 

Here is a code module that handles it :

Option Explicit

' 32-bit EZTWAIN functions for Visual Basic 5.0

' Acquires a single scan and returns it as a DIB handle
Declare Function TWAIN_AcquireNative Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal wPixTypes%) As Integer

' Releases the storage for a DIB handle
Declare Sub TWAIN_FreeNative Lib "EZTW32.DLL" (ByVal hdib%)

' Acquires a single scan and places it on the clipboard as a DIB
Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal wPixTypes%) As Integer

' Acquires a single scan and writes it to a .BMP file
' If bmpFileName$ is empty, prompts user for filename.
Declare Function TWAIN_AcquireToFilename Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal bmpFileName$) As Integer
   
' Posts the standard TWAIN Select Source dialog
Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp%) As Integer

' returns 1 if TWAIN is available on host system, 0 otherwise.
Declare Function TWAIN_IsAvailable Lib "EZTW32.DLL" () As Integer

' returns the EZTWAIN version * 100 i.e. 105 for version 1.05
Declare Function TWAIN_EasyVersion Lib "EZTW32.DLL" () As Integer

' returns the TWAIN state - see TWAIN.H or EZTWAIN.H
Declare Function TWAIN_State Lib "EZTW32.DLL" () As Integer

Declare Function TWAIN_WriteNativeToFilename Lib "EZTW32.DLL" (ByVal hBitmap%, ByVal bmpFileName$) As Integer

' returns the number of bits per pixel of a DIB (given the DIB handle)
Declare Function TWAIN_DibDepth Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the width in pixels of a DIB (given the DIB handle)
Declare Function TWAIN_DibWidth Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the height in pixels of a DIB (given the DIB handle)
Declare Function TWAIN_DibHeight Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the size of the colortable of a DIB (given the DIB handle)
' DIBs deeper than 8 bits have no colortable and will return 0.
Declare Function TWAIN_DibNumColors Lib "EZTW32.DLL" (ByVal hdib%) As Integer



'--------------------
' TifDLL Error Codes
'--------------------

Public Function TiffError(ByVal R As Long) As String

    Select Case R
        Case 32501
            TiffError = "Unspecified Internal Error"
        Case 32502
            TiffError = "Unsupported Image Format (Please check the files with DIL extensions)."
        Case 32504
            TiffError = "File Not Found"
        Case 32506
            TiffError = "Insufficient Memory"
        Case 32210
            TiffError = "File Already Exists"
        Case 32211
            TiffError = "Error Opening File"
        Case 32511
            TiffError = "Error Printing Image"
        Case 32515
            TiffError = "Missing DIL file"
        Case 33202
            TiffError = "Missing DEL file"
        Case 33203
            TiffError = "Unsupported Export Format (please check the files with DEL extensions)."
        Case 33205
            TiffError = "Insufficient Memory"
        Case 33208
            TiffError = "Bad Dynamic Export Library"
        Case Else
            TiffError = "Unknown TiffDLLError " & Format$(R)
      End Select


End Function

and here is code that handles scans a picture to file :

Public Function ScanPictureToFile(ByVal FileName As String) As String


   On Local Error Resume Next

   Dim foo As Integer
   Dim F As Integer
   Dim c As String
   Dim R As Long
   
   
   FileName = Trim$(FileName)
   If Len(FileName) = 0 Then
     ScanPictureToFile = "The filename to save the file to is invalid."
     Exit Function
   End If
   F = FreeFile
   Open FileName For Output As #F
   Print #F, "Test"
   Close #F
   Kill FileName
   If Err <> 0 Then
     Err = 0
     ScanPictureToFile = "The picture cannot be save to the specified filename. Error is " & Error$(Err)
     Exit Function
   End If
       
   Screen.MousePointer = vbHourglass
   Clipboard.Clear
   foo = TWAIN_AcquireToClipboard(ByVal 0, ByVal 0)
   If (foo = 0) Then
      ScanPictureToFile = "A Problem was encountered while attempting to aquire the image. Please try again."
      Screen.MousePointer = vbDefault
      Exit Function
   End If
   
   Image1.Picture = Clipboard.GetData(vbCFDIB)
   Clipboard.Clear
   If Err <> 0 Then
     ScanPictureToFile = "An Error occurred while transferring the image from the clipboard to memory. The problem was identified as " & Error$(Err)
     Screen.MousePointer = vbDefault
     Exit Function
   End If
   
   If StrComp(Format, "bmp", vbTextCompare) = 0 Then
     SavePicture Image1.Picture, FileName
     If Err <> 0 Then
       ScanPictureToFile = "An Error occurred while attempting to save the image. The problem was identified as " & Error$(Err)
       Screen.MousePointer = vbDefault
       Exit Function
     End If
     ScanPictureToFile = "" 
     Exit Function
   End If
   
   
   Screen.MousePointer = vbDefault
   ScanPictureToFile = "" 

End Function

For this to work, you need to have an Image Control called Image1 on the form where you implement the function. I grabbed this from some code I wrote around 2 years ago. It actually uses another library to save as GIF, JPG or so but as it's commercial I had to strip it from this code. I hope the stripping did not introduce any errors

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1524131
Search criteria: +"visual basic question" vb +scanner -wang

Result: 20 topics

http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10110893 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10081983 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10162826 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10170596 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10170442 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10107104 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10162093 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10136911 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10139532 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10168053 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10021177 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10110368 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10133727 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10138242 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10145160 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10165813 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10011091 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10026978 
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10066816 

Want to perform another search?
Take a look at http://www.experts-exchange.com/jsp/qShow.jsp?ta=commspt&qid=10167777 

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question