How to C#: Tiff
Using Tiff SDK for C#.NET
Create, Load, and Save Tiff File
Create, Load, and Save Tiff File
  |  
Home ›› XDoc.Tiff ›› C# Tiff: Create, Load and Save

C# TIFF - Create, Load and Save TIFF File


How to Load, Create and Save TIFF Image File Using C#.NET Programming




RasterEdge.XDoc.Tiff.dll empowers C# programmers with various Tiff imaging functionalities. To start with, you may need to create or load a Tiff document into your Visual C# project. Then, do advanced settings like viewing, annotating, converting, processing, etc. And finally, save the Tiff image file to byte array, stream or local file.

Related .net document control helps:
asp.net powerpoint viewer: ASP.NET PowerPoint Document Viewer Control (MVC & WebForms): view ppt, pptx files online in C# using ASP.NET
asp.net text file viewer: ASP.NET Text file viewer in MVC, WebForms: Open, view, annotate, convert txt files in C# ASP.NET
asp.net pdf page: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net mvc pdf editor: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net word viewer: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
asp.net excel viewer: ASP.NET Excel Viewer in C# Control (MVC & WebForms): view Office Excel document in web browser.
asp.net sharepoint document viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint

On this page, you will be guided to create or load a Tiff document in your C#.NET windows or web application. In addition, Tiff document saving demo is also provided. For more Tiff document reading and manipulating tutorials, please see Tiff File in C#.NET.




C# Project DLLs: Create, Load and Save TIFF File



In order to run the following conversion code, please do as follows:


Add references;


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.XDoc.Processing.dll


  RasterEdge.Imaging.Raster.dll


  RasterEdge.Imaging.Raster.Core.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.TIFF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.TIFF;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:


If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.


If using x86, the platform target should be x86.




C# TIFF - How to Create TIFF Image File



This piece of C# coding example is used to create a TIFFDocument object include 3 pages.




// Create a TIFFDocument object include 3 pages.
int pageCount = 3;
TIFFDocument doc = new TIFFDocument(pageCount);
if (null == doc)
        throw new Exception("Fail to create TIFF Document");





C# TIFF - How to Load TIFF Image File



XDoc.Tiff for .NET provides advanced APIs for C# programmers to load TIFFDocument from file, stream, byte array, Bitmap object array, and FileIOMgr handler. Please see demo code as below.




// Load a TIFFDocument from file.
string filePath = "demo.tif";
TIFFDocument doc = new TIFFDocument(filePath);
if (null == doc)
        throw new Exception("Fail to load TIFF Document");

// Load a TIFFDocument from stream.
FileStream stream = new FileStream("demo.tif", FileMode.Open, FileAccess.Read);
TIFFDocument doc = new TIFFDocument(stream);
if (null == doc)
        throw new Exception("Fail to load TIFF Document");

// Load a TIFFDocument from byte array.
byte[] array = File.ReadAllBytes(@"demo.tif");
TIFFDocument doc = new TIFFDocument(array);
if (null == doc)
        throw new Exception("Fail to load TIFF Document");





C# TIFF - How to Save TIFF Image File



After manipulations, you can easily save TIFFDocument to file (with defined path), stream or byte array.




// Save TIFFDocument to file with defined path.
TIFFDocument doc = new TIFFDocument("demo.tif");
doc.Save(@"output.tif");

// Save TIFFDocument to byte array.
byte[] result = doc.SaveToBytes();

// Save TIFFDocument to stream.
MemoryStream stream =new MemoryStream();
doc.SaveToStream(stream);



public TIFFDocument(string fileName)

Description:
Create TIFF Document object from file path.

Parameters:
public TIFFDocument(byte[] fileData)

Description:
Create TIFF file from byte array, but the byte array must be a valid TIFF file.

Parameters:
public TIFFDocument(Stream stream)

Description:
Create a TIFF file from stream, but the stream must be a valid TIFF file.

Parameters:
public TIFFDocument(Bitmap[] images, ImageCompress imageCompression)

Description:
Create TIFF file from images with specified compression.

Parameters:
public TIFFDocument(Bitmap[] images, ImageOutputOption options)

Description:
Create TIFF file from images with option setting.

Parameters:
public override void Save(string filePath)

Description:
Save TIFF document object to the given file path.

Parameters:
public override void SaveToStream(Stream stream)

Description:
Save TIFF document object to stream.

Parameters:
public override byte[] SaveToBytes()

Description:
Save TIFF document object to byte array.

Return:
A byte array, null if failed.