C#: Online Guide
How To: Twain SDK
Specify Size and Location to Scan
Specify Size and Location to Scan
Home ›› XImage.Twain ›› C# Twain: Specify Size and Location to Scan

C# TWAIN - Specify Size and Location to Scan

How to Save Acquired Image to File in C#.NET with TWAIN Add-on

C# TWAIN Image Acquisition Application

This C#.NET TWAIN image acquiring library add-on owns the ability to specify developer's need to define the scanning size and location using Visual C# .NET programming language. This online article will illustrate how to determine C# TWAIN image scanning area and location with a series of C# demo codes.

Related .net document control helps:
asp.net dotnetnuke pdf editor using c#: ASP.NET DNN PDF Editor Control: view, edit PDF files in Dotnetnuke application
c# asp.net text document viewer: C# HTML5 Viewer: Load, View, Convert, Annotate and Edit OpenOffice, CSV and Text file
c# asp.net tiff document viewer: ASP.NET Tiff Document Viewer: view, annotate Tiff files in HTML using C# Control
asp.net document viewer in c#: EdgeDoc ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online using ASP.NET Web Con...
asp.net annotate pdf using c#: ASP.NET Annotate PDF Control: annotate, comment, markup PDF document online using ASP.NET C#
c# asp.net dicom document viewer: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET
c# asp.net document annotation: ASP.NET Document Annotation Control: text comment, drawing on files online using ASP.NET component

Preparation for Setting C# TWAIN Scanning Size & Location

The preparation of setting C# TWAIN image scanning size and location contains two parts. One is the system developing environment and the other is the C# TWAIN scanning application requirements.

System Requirements for C# TWAIN Image Scanning

To make sure that RasterEdge C# TWAIN image scanning library SDK can work stably and successfully in your C# imaging application, please meet following developing requirements first.

  Have installed .NET Framework 2.0, 3.0, 3.5, 4.0 or 4.5

  Have installed Microsoft Visual Studio 2005, 2008, 2010 or 2012

  Have installed TWAIN

  Have installed RasterEdge C# TWAIN image scanning SDK

  Have installed at least one TWAIN compatible device

  Have put valid developing license key at the right place

Application Requirements for C# TWAIN Image Scanning

After you meet above mentioned system requirements, then you have to ensure that you have finished following tasks.

  Get the Device object of source TWAIN device. To view detailed C# programming guidance, please follow this link to C# TWAIN Device object creation

  Open a connection to target Device object. Detailed Visual C# .NET demo code for setting TWAIN device connection can be found at this tutorial page of how to open & close connection to TWAIN device

How to Set C# TWAIN Scanning Size & Location

C# TWAIN image scanning control add-on owns the capacity to help developers define where the TWAIN scanning will start and how much area will the image scanning process cover. Just as is mentioned in above section, please make sure you have opened a connection to source Device object.

Note: RasterEdge defines each TWAIN compatible device as a Device object, which can be only created through methods offered by Acquisition class (constructor for TWAIN image acquisition). And each Device object contains APIs that control various TWAIN device capabilities.

If you are a VB.NET developer, you may see online tutorial for Setting Image Size and Location in VB.NET TWAIN Scanning Project.

C# Demo Code to Set TWAIN Image Scanning Size

Using this TwainStaticFrameSizeType method, you can get a list of available frames supported by target TWAIN device in C# project. Then you can choose one that fits your TWAIN image scanning need.

/// <summary>
/// suppose the device is opened
/// </summary>
public void SpecifySizeToScan(Device device)
   // Get a list of supported frames and choose the one that fits your needs.
   TwainStaticFrameSizeType[] frames = device.GetSupportedFrameSizes();
   foreach (TwainStaticFrameSizeType frame in frames)
      if (frame == TwainStaticFrameSizeType.LetterUS)
            this.device.FrameSize = frame;

C# Demo Code to Customize TWAIN Scanning Area & Location

Following sample C# code can help you decide the TWAIN image scanning size and location at a time. Using TwainUnitType method, you can get a collection of supported measurement units. Then you can choose your desired measurement unit. After decide the measurement unit, you can accurately determine the TWAIN image scanning area by calling the RectangleF method.

/// <summary>
/// suppose the device is already opened
/// </summary>
/// <param name="device"></param>
public void SpecifyLocationAndSizeToScan(Device device)
   device.Units = UnitType.Inches;
   if (device.Units != TwainUnitType.Inches) return;
   device.Frame = new System.Drawing.RectangleF(0, 0, 8.5, 11);