Results 1 to 27 of 27

Thread: Scan in VB.NET

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Scan in VB.NET

    Hello.
    I am trying to scan images in VB.NET. I searched this site for almost an hour and found questions, but little in the way of answers, but some redirection which did not resolve the issue.

    I downloaded the example here http://www.codeplex.com/openTwain which has 7 projects doing a whole bunch of things. I do not have the scanner attached to my PC. Nor can I run any of these examples which do way more than I am trying to do.

    Then I went here http://www.codeproject.com/KB/dotnet/twaindotnet.aspx, found the VB version on planetsourcecode, but it will not run. I tried to duplicate what it does, but I couldn't get either of these line to be recognized:
    Code:
    Imports TwainGui.vb.TwainLib
    Imports TwainGUI.vb.GdiPlusLib
    I am a VB.NET novice, but a VB veteran since VB3. I understand that the differences between .NET and VB are huge, but what I fail to understand is why no one has been able to post an example of how to scan? My company is not willing to purchase any 3rd party tools and my boss believes it can be done through the api, which some posts seem to imply but fail to show how.

    Can anyone please help me?

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    No one know how to scan on this site? lol I found a free dll that uses twain that I haven't seen posted anywhere here. Here's the link for anyone who may need it: http://www.dosadi.com/eztwain1.htm. Its hard to beat free, and it requires no installation apart from putting the dll in your app directory (or system32). The ease of installation makes it the preferable choice over WIA.

    I declared it like this:
    Code:
        Private Declare Function AcquireNative Lib "eztw32.dll" Alias "TWAIN_AcquireNative" ( _
           ByVal hwndApp As Integer, _
           ByVal wPixTypes As Integer) As Integer
    
        Private Declare Function AcquireToFilename Lib "eztw32.dll" Alias "TWAIN_WriteNativeToFilename" ( _
           ByVal hwndApp As Integer, _
           ByVal sFile As String) As Integer
    
        Private Declare Function AcquireToClipboard Lib "eztw32.dll" Alias "TWAIN_AcquireToClipboard" ( _
            ByVal hwndApp As Integer, _
            ByVal wPixTypes As Integer) As Integer
    If I can get this to scan multiple pages I will be all set. I would also like to remove the dialog. I will post any solutions here that I find. Does anyone have any knowledge using this dll or know of a link?

    If there isn't a way to scan multiple pages with this free dll then I will use WIA.

    Thanks for looking

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    Looks like I may be stuck with WIA. But a working COM is better than a not working DLL. But if anyone needs to scan a single page, eztwain works well. Requires no extra steps for the setup as long as the DLL is placed where the app can find it. Here's the code:
    Code:
             Private Declare Function AcquireNative Lib "eztw32.dll" Alias "TWAIN_AcquireNative" ( _
                  ByVal hwndApp As Integer, _
                  ByVal wPixTypes As Integer) As Integer
    
             Private Declare Function AcquireToFilename Lib "eztw32.dll" Alias "TWAIN_WriteNativeToFilename" ( _
                  ByVal hwndApp As Integer, _
                  ByVal sFile As String) As Integer
    
            Private Declare Sub FreeNative Lib "eztw32.dll" Alias "TWAIN_FreeNative" ( _
                 ByVal hdib As Integer)
    
            intHandle = AcquireNative(Me.Handle, 0)
            rc = AcquireToFilename(intHandle, AppPath() & "Scan.bmp")
            FreeNative(intHandle)
    If I get WIA to work I will post that for others to use.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    WIA doesn't work with our scanner. Does anyone know how to scan? It seems there is no one on this site who knows how to scan. Perhaps this isn't a good forum for scanning questions. Can anyone redirect me to a forum where someone may have some knowledge on scanning?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    This can be closed. I will post my progress on a more advanced forum.

  6. #6
    New Member
    Join Date
    Jun 2009
    Posts
    13

    Re: Scan in VB.NET

    Dear MarMan,

    i am in a similar position to you. Did you post your question on a more advanced forum? if so have you had any replies??

    I would be grateful if you could let me know if you have had any luck finding any tutorials or solutions to scanning with WIA in VB.net

    Many thanks

    James

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    I didn't use WIA, I used TWAIN. And I did post in other forums, but didn't get any help. It seems no one else who posts to the forums is attempting anything like this. After much trial and error, I was able to get it working. The biggest difficulty for me was passing data from managed code (.NET) to unmanaged code (TWAIN dll). You have to manually pack and unpack the structures yourself. I can't help you with WIA, but can help with TWAIN. Just post any questions to this topic and I will be notified.

  8. #8
    New Member
    Join Date
    Aug 2010
    Posts
    2

    Re: Scan in VB.NET

    HI Marman

    I am using Twain and facing problem scanning multiple pages in one PDF or TIFF. Can you help me with this if you have any solution?

    Thanks
    Nilesh

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    I don't know if I can help you, since my task required separate files. I did develop a class to scan that I was planning to post in the codebank, I'll post it if you wish to look at it. It scans 1 image per file.

    I'll help you if I can, I know I needed the help when I was developing the class, but it is cheaper to buy a third party control, so not too many people delve into this and I received very little help.

    How do you do multiple images, is it a capability adjustment?
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  10. #10
    New Member
    Join Date
    Aug 2010
    Posts
    2

    Re: Scan in VB.NET

    that means your class doesnt scan multiple documents in one file?

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    My class can (untested) do anything TWAIN can do. I just never had any need to scan multiple images into one file. TWAIN supports many things that individual scanners do not. Does your scanner support it? And if it does, do you know the proper capabilities to set to accomplish it? That is a reqiuirement.

    My class can set capabilities, which was no trivial task.

    If you wish to have a go at setting capabilities it would be eaiser in VB6 because if you use .NET you have to manually pack and unpack the structures yourself because of the managed code / unmanaged code boundry.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  12. #12
    New Member
    Join Date
    Aug 2010
    Posts
    1

    Re: Scan in VB.NET

    Did you ever get the code class and an example posted? I believe that you may have hit on something that is perfect for me. Thanks A Lot,

    Rickey Bell
    Paramedic

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    It's too big. See attachment.
    Attached Files Attached Files
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  14. #14
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Scan in VB.NET

    The code at http://www.codeproject.com/KB/dotnet/twaindotnet.aspx worked perfectly for me. After making a few adjustments, I was able to scan several documents in one scan and also handle two-sided scans. I haven't gone into saving in a PDF.
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    Saw that code but never tried it. The project I was working on required VB. Options are good!
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  16. #16
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Scan in VB.NET

    You can turn it to a C# DLL and then use the DLL. That's what I did.
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    That works. But my boss made it clear they wanted no third party controls and all code done in VB.NET. So I did it. Forgot about that C# example. It may be good enough for their needs.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  18. #18
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: Scan in VB.NET

    You may also get the code, convert it to VB.Net and use it in your application. I don't understand the fuzz about third-party controls if you have the code to them.
    "Feel the force...read the source..."
    Utilities: POPFile • DebugView • Process Explorer • Wireshark • KeePass • UltraVNC • Pic2Ascii
    .Net tools & open source: DotNetNuke • log4Net • CLRProfiler
    My open source projects: Thales Simulator • EFT Calculator • System Info Reporter • VSS2SVN • IBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    Did you try converting it? I bet it is significantly more work than it seems. Simple things convert easily, but something like that can be a job and a half. I wouldn't even attempt it. I'll bet you get 102 errors.

    As far as 3rd party controls go, quite often you are limited because marketing has this "time to market" that they devise without consulting any programmers. So things get cut, as long as its not something you need, good. Sometimes it is. Not many 3rd party controls give the source code. If they did, someone would plagiarize it. Then you can take it without knowing and without buying the source. Company out-of-business. And I didn't even bring up licensing and upgrading issues, which are much less of a problem if you own and wrote the code.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  20. #20
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Scan in VB.NET

    I have converted that C# project into VB.Net. But haven't done anything with the designing and other stuff of the forms.
    It needs some more tidying up of that code.

    I used this converter.

    Attached Files Attached Files

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  21. #21

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    That's my preferred converter. Do you try the code akhil?
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  22. #22
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Scan in VB.NET

    Quote Originally Posted by MarMan View Post
    That's my preferred converter. Do you try the code akhil?
    No, I haven't tested the code yet as I have no access to my scanner at the moment. Will test it soon(not now).


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  23. #23
    New Member
    Join Date
    Apr 2012
    Posts
    3

    Re: Scan in VB.NET

    Please tell me how to use Scan.doc to build the Project because a can't the fmrMain.vb file.
    Thanks alot!
    Quote Originally Posted by MarMan View Post
    It's too big. See attachment.

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Scan in VB.NET

    There is no frmMain. It is a scanning class. If you wish a frmMain then you need to create one yourself.

    The first set of CODE tags is clsScan.
    The second set is clsLogging. I don't remember why I included that.
    The third set is an example on how to use.
    The fourth example is how to set up a property to receive the pictures.
    The rest I believe is optional.

    The fourth example is an example only. It calls functions that are not there, but may not be needed. You need to figure out what you want to do with the data after its scanned. Save to disk? Display on screen?

    I don't have a scanner hooked up right now since I completed this project awhile ago but I will help anyway i can. Be sure to read the instructions between code tags. Search for "CODE]" without the quotation marks.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  25. #25
    New Member
    Join Date
    Apr 2012
    Posts
    3

    Re: Scan in VB.NET

    Thanks you, I will to try

  26. #26
    New Member
    Join Date
    Apr 2020
    Posts
    1

    Re: Scan in VB.NET

    Quote Originally Posted by MarMan View Post
    It's too big. See attachment.
    Hi sir,

    May I ask for the sample form that displays and calls the classes you've made? I've already tried your codes, it worked and able to communicate with scanner but after scanning, It stop there, no displays of the scanned documents and I don't know to find the files i've scanned.

    Please need your help sir.

  27. #27
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,027

    Re: Scan in VB.NET

    The thread was started a decade back and hasn't had any activity for eight years. You might get lucky, but don't hold your breath.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width