שתף באמצעות


Is there a built-in TWAIN Scanning library in .Net 4 to use it in VB.NET

Question

Friday, June 1, 2012 9:05 PM

Hi,

I would like to know if there is a built-in TWAIN Scanning library in .Net 4 to use it in VB.NET.

Thanks

All replies (7)

Friday, June 1, 2012 9:18 PM ✅Answered

There's not built-in support for TWAIN in .NET, you can use a wrapper library of the twain_32.dll Windows API:
http://opentwain.codeplex.com based on http://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner.

Matteo Migliore

Bloghttp://blogs.ugidotnet.org/matteomigliore
Twitterhttp://twitter.com/matteomigliore
CodePlex

http://hyperionsdk.codeplex.com http://sample.codeplex.com


Monday, June 25, 2012 7:10 AM | 2 votes

Dynamic .NET TWAIN is a TWAIN Scanning library designed for .Net platform. 


Tuesday, June 4, 2013 10:30 AM | 1 vote

For those who want to call TWAIN library from .NET, this article might help:
http://www.dynamsoft.com/blog/document-imaging-how-to/using-twain-in-net-applications/

Catherine Sea


Thursday, December 5, 2013 7:37 PM

Saraff.Twain.NET (sarafftwain.codeplex.com) is the skilful scanning component which allows you to control work of flatbed scanner, web and digital camera and any other TWAIN device from .NET environment.

Features:

  • Programming environments: .NET Framework 2.0 or higher
  • This is a fully-managed .NET library to guarantee the fast working in .NET Framework
  • Acquire images from scanners, web or digital cameras and any other TWAIN device
  • Data source enumeration and selection
  • Set up images acquisition parameters (pixel type, resolution, page size, image layout rectangle, brightness, contrast, etc)
  • Control advanced capabilities of TWAIN devices (rotation of images, scaling of images, filters of images, paper handling, the patch code detection and etc)
  • Save acquired images as BMP, JPEG, PNG, GIF, TIFF files

You can use this library in your programs written in any programming languages compatible with .NET technology.

с форума TechNet


Friday, December 20, 2013 12:15 AM

I found a project online that uses TWAIN APIs.  The solution is TwainGUI.sln.  You might search for that.  I was not able to view the form that displays scanned images (MDI child) in design view.  But it did display the image on the form's background when running.  Rotating images was a pick of cake.  But I couldn't get the program to display the rotated image.

I ended up add code from that project to one I'd already designed to display images.  As soon as it completed a scan, I had it save it to a file.  To rotate it I used Bitmap.FromFile to load it into a bitmap object, used the RotateFlip method to rotate, and saved it.  To crop out parts of the image, I had the program call msPaint, did the editing, and clicked Save.  When I close Paint, the cropped image shows.

When I tried doing a third scan, the code returned the image from the second scan, even though the new scan showed in the preview.  If I closed the project and reran it, scanning worked (for the next two scans).  I added this method to TwainLib.vb.  It appears to have fixed the problem.

   

PublicSubReset(ByValhwndp AsIntPtr)

Dimrc AsTwRC= DSMparent(appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, hwndp)

        rc = DSMparent(appid,

IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, hwndp)

       

If(rc = TwRC.Success) Then

            rc = DSMident(appid,

IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.GetDefault, srcds)

       

If(rc = TwRC.Success) Then

                hwnd = hwndp

Else

                rc = DSMparent(appid,

IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.CloseDSM, hwndp)

    

EndIf

 

EndIf

EndSub


Tuesday, August 23, 2016 3:18 PM

There are quite a number of TWAIN scanning libraries. However, most don't work for 64bit applications. If you need to support x64 .NET WinForms or WPF, you should definitely check out Asprise C# VB.NET scanner access and imaging SDK for Windows 32bit and 64bit.

Sample code for access TWAIN WIA document scanners from VB.NET:

Imports asprise_imaging_api

Dim result As Result = New AspriseImaging().Scan(New Request()
   .SetTwainCap(TwainConstants.ICAP_PIXELTYPE, TwainConstants.TWPT_RGB)
   .SetTwainCap(TwainConstants.ICAP_SUPPORTEDSIZES, TwainConstants.TWSS_USLETTER)
   .SetPromptScanMore(True) ' prompt to scan more pages
   .AddOutputItem(New RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_JPG)
      .SetSavePath(".\${TMS}${EXT}")), ' Environment variables in path will be expanded
  "select", True, True) ' "select" prompts device selection dialog.

Dim files As List(Of String) = If(result Is Nothing, Nothing, result.GetImageFiles())
Console.WriteLine("Scanned: " & String.Join(", ", If(files Is Nothing, New String(-1) {}, files.ToArray())))

Read developer's guide to C# VB.NET web twain wia scanner access ...


Wednesday, August 24, 2016 3:22 AM

There are quite a number of TWAIN scanning libraries. However, most don't work for 64bit applications. If you need to support x64 .NET WinForms or WPF, you should definitely check out Asprise C# VB.NET scanner access and imaging SDK for Windows 32bit and 64bit.

Sample code for access TWAIN WIA document scanners from VB.NET:

Imports asprise_imaging_api

Dim result As Result = New AspriseImaging().Scan(New Request()
   .SetTwainCap(TwainConstants.ICAP_PIXELTYPE, TwainConstants.TWPT_RGB)
   .SetTwainCap(TwainConstants.ICAP_SUPPORTEDSIZES, TwainConstants.TWSS_USLETTER)
   .SetPromptScanMore(True) ' prompt to scan more pages
   .AddOutputItem(New RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_JPG)
      .SetSavePath(".\${TMS}${EXT}")), ' Environment variables in path will be expanded
  "select", True, True) ' "select" prompts device selection dialog.

Dim files As List(Of String) = If(result Is Nothing, Nothing, result.GetImageFiles())
Console.WriteLine("Scanned: " & String.Join(", ", If(files Is Nothing, New String(-1) {}, files.ToArray())))

Read developer's guide to C# VB.NET web twain wia scanner access ...

I'm not so sure that hawking your own paid app is desired here - I'll let a moderator decide that.