C#: Online Guide
How To: Twain SDK
Query Device Abilities
Query Device Abilities
Home ›› XImage.Twain ›› C# Twain: Query Device Abilities

C# TWAIN - Query & Set Device Abilities in C#

C# TWAIN Scanning SDK to Query & Set Device Abilities in .NET TWAIN Application

C# TWAIN: Query & Set Device Capabilities Overview

Why do we need to query TWAIN device capabilities? If you just need to build a basic TWAIN image capturing process for your Visual C# .NET class application, then, there is no need to query TWAIN device properties. But if you want to customize your TWAIN image acquisition process, you have to know what abilities are supported by source TWAIN device and create your own featured TWAIN scanning dialog based on query results.

Related .net document control helps:
asp.net mvc image viewer: ASP.NET Image Viewer Control（MVC & WebForms）: view, annotate, redact, convert image files in html, JQuery
asp.net dicom library: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET
asp.net edit pdf image control: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#
asp.net edit pdf page control: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net view excel in browser: ASP.NET Excel Viewer in C# Control (MVC & WebForms): view Office Excel document in web browser.

To put it in another way, the purpose of querying and setting TWAIN device properties is to specify the image acquiring needs. Using this C# TWAIN image scanning SDK, developers can easily and quickly find out what compression modes, frame sizes, resolutions and other capabilities, like automatic scanning, are supported by source TWAIN device. For example, after you create a Device object and open a connection to source TWAIN device, you will know whether target TWAIN device supports duplex scanning. If the query result is true, you can set and integrate this duplex scanning feature into your C# TWAIN image acquisition application. If the query result is false, then you know your TWAIN image scanning application is unable to support duplex scanning.

What should be noted here is that, different from other common C# TWAIN image scanning control add-ons, RasterEdge .NET TWAIN image acquisition library toolkit allows developers to integrate some image scanning features that are not supported by target TWAIN device. For example, when you find out what file types are supported by source TWAIN device, the query result tells you that only jpeg image format is supported. But you want to save acquired image object to file as TIFF file in C#.NET. Then, does it mean that you can not save TWAIN scanned image object to desired TIFF file format? Of course, the answer is no.

As RasterEdge .NET Image SDK Core DLLs support several image compression algorithms, which allow you to save captured image object to certain common image format in C# TWAIN scanning project, like jpeg, tiff, bmp, png or gif, even though the desired image format is not supported by source TWAIN compatible device.

Get & Set TWAIN Device Capabilities in C#

In this section, we will tell you how to get and set TWAIN device properties using C# TWAIN image acquiring library add-on step by step. For VB.NET online guide, please refer to Query & Set TWAIN Device Abilities in VB.NET.

How to Query TWAIN Device Properties in C#

From this part, you will know the basic steps for querying and setting source TWAIN device capabilities using Visual C# .NET programming language.

  As the querying process for C# TWAIN device abilities is mainly conducted in the level of TWAIN Device Control, you have to create a connection to source Device object before you get and set properties of source TWAIN device;

  Find out whether desired image scanning property is supported by source C# project TWAIN device;

  If desired image scanning capability is not supported, tell the application to close the connection to device;

  If desired image acquiring feature is supported, set the property for TWAIN image acquisition using C# code and then remember to close the connection after the image acquiring process.

C# Demo Code for Setting TWAIN Device Abilities

In this section, we offer you a sample C#.NET programming example which is used to find out what file formats developers can save TWAIN scanned image object to. To help you better understand following demo C# code, we here expressly illustrate one programming class for you, which is Device object. A Device object, an abstraction for representing one TWAIN compatible device, can be only created through the methods provided from C# TWAIN Acquisition Object APIs.

public void QueryDeviceCapabilities(Device device)
   // Open a connection to the device.
   device.TransferMode = TwainTransferMode.TWSX_NATIVE;

   // See if the device supports file transfer.
   TwainTransferMode[] methods =
   foreach (TwainTransferMode method in methods)
      if (method == TwainTransferMode.TWSX_FILE2)
            // Use TWSX_FILE2 when possible.
            device.TwainTransferMode = method;

            if (method == TwainTransferMethod.TWSX_FILE)
            device.TransferMethod = method;

   // If it's not supported tell stop.
   if (device.TransferMode == TwainTransferMode.TWSX_NATIVE)
      // Close the connection.
      Console.WriteLine("File Transfer not supported");

   // Find out which file types the device can save to.
   TwainImageFormat[] formats = device.GetSupportedImageFormats();
   // We want to save the image as a TIFF.
   foreach (TwainImageFormat format in formats)
      if (format == TwainImageFormat.Tiff)
            // TIFF is supported, so set the FileFormat.
            device.FileFormat = format;
            // Now lets try to use Group4 or Group3 compression.
            // We could use GetSupportedCompressionModes, but we
            // will simply try setting the Compression property instead.
            device.Compression = TwainCompressionMode.Group4;
            if (device.Compression != TwainCompressionMode.Group4)
            device.Compression = TwainCompressionMode.Group3;

   // Start the acquire process, using the device's interface.

   // don't forget to close the connection after done