C# TIFF Image Library
Create, Load and Save TIFF File
How to Load, Create and Save TIFF Image File Using C#.NET Programming
Overview
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.
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:
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);
|
Related API(s) (TIFFDocument.cs):
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.