C#: Online Guide
How To: Twain SDK
Acquire Image to File
Acquire Image to File
  |  
Home ›› XImage.Twain ›› C# Twain: Acquire Image to File

C# TWAIN - Acquire or Save Image to File


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




Overview - Save Image to File with C# TWAIN Device



RasterEdge C#.NET TWAIN Add-On enables developers to directly acquire image to file with a couple of code lines in C# programming project. Using this C#.NET TWAIN Add-On, you are capable of scanning images from digital imaging devices (such as TWAIN compatible scanners and digital cameras) automatically and saving the images to file in C#.NET application.


Related .net document control helps:
asp.net pdf file viewer: ASP.NET PDF Document Viewer in C#: view, annotate, redact Adobe PDF files online in ASP.NET
asp.net webforms pdf editor control: ASP.NET WebForms PDF Editor: create, view, edit, annotate, redact PDF file in ASP.NET WebForms application
asp.net webforms file viewer: ASP.NET WebForms application document viewer control: view, annotate, redact, convert 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 azure pdf editor control: ASP.NET Azure PDF Editor Control: view, edit, annotate, redact PDF files online
asp.net dotnetnuke pdf editor control: ASP.NET DNN PDF Editor Control: view, edit PDF files in Dotnetnuke application


If you want to acquire an image directly into the C#.NET application in which you are going to work with the image, you'd better use the widely used application programming interface - TWAIN. TWAIN is not a hardware-level protocol, but a communication protocol that realizes connection between software and digital imaging devices. Our C#.NET TWAIN Add-On supports acquiring or saving image to file by using compression algorithm supported by the device.




TWAIN Preparation - Acquire Image to File in C#



DLLs for Saving Image to File with C# TWAIN Add-On


If you have a demand of directly acquiring image to file in C#.NET application, you are free to download our C#.NET TWAIN Add-On evaluation package for trial. To use this advanced Add-On to acquire image to file in C#.NET program, you need to add the following dlls to your Visual C#.NET project.


  RasterEdge.XImage.BarcodeScanner.dll


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XDoc.PDF.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.Imaging.WinformsControl.Twain.dll


Product Licenses Used to Acquire Image to File in C#.NET


If you want to apply our C#.NET TWAIN Add-On to commercial applications, you need to purchase RasterEdge .NET Imaging SDK license and TWAIN Add-On license. One license is designed for a single named developer. If there are more developers who want to use our .NET Image SDK, additional licenses should be purchased based on the number of developers. We also offer server licenses for server applications or service applications that support connections from other machines.


Environment for Saving Image to File Using C# Class


In addition to .NET Framework 2.0 or later versions and Visual Studio version 2005 to 2012, there are other environment requirements for applying this TWAIN Add-On in C#.NET programs. For example, you need to check whether TWAIN is installed in your system and at least one TWAIN compatible device is present.




C#.NET Demo Code for Saving Image to File



The following C#.NET demo code can be used to acquire image to file using our C#.NET TWAIN Add-On. First of all, check supportive image format is necessary in order to set the file format later. Then, developers can choose the supported compression mode or simply set the compression properties.




public void AquireToFile()
{
   Acquisition acq = new Acquisition();

   Device device = acq.ShowSelectSource();
   // Find out supportive image formats.
   TwainImageFormat[] formats  = device.GetSupportedImageFormats;

   foreach (TwainImageFormat format in formats)
   {
      if (format == TwainImageFormat.Tiff)
      {
      // Set the FileFormat.
      device.FileFormat = format;
      // Now let's 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;
      break;
      }
   }

   acq.FileTranfer += new EventHandler(OnFileTransfer);

}





C#.NET Demo Code for Setting the File Path



Developers are able to set the file path to store the acquired image based on own needs. For example, you can use C#.NET sample code below to store the acquired image to TIFF image format in ScanningImage folder under hard disc C.




/// <summary>
/// Set the file path to store the image acquired.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void OnFileTransfer(object sender, FileTransferEventArgs e)
{
   e.FileName = @"C:\ScanningImage\newImage.tif";
}