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:
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.
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.
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.
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?
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.
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?
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.
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.
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.
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.
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.
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.
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
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
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.
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.