How to Create/Save Raster Image as TIFF with Deflate/Adobe Deflate Compression
This Technical tip explains how .NET developers can create, save and load raster Image as TIFF using Deflate/Adobe Deflate Compression methods inside their .NET applications using Aspose.Imaging for .NET. The TIFF (Tagged Image File Format) file format supports various types of compression whereas the compression type is stored as a tag (an integer value) in the file. One of such compression methods is Adobe Deflate (previously known as Deflate). Since the release of Aspose.Imaging for .NET 2.6.0, the API supports this compression method for loading, converting & creating TIFF images. Aspose.Imaging for .NET API hides all the ugly details from the user and provides an easy to use mechanism to load images for further processing.
//your code here...//Saving a Raster Image to TIFF with Deflate/Adobe Deflate Compression
// [C# Code Sample]
string sourceFilePath = myDir + "sample.bmp";
string destinationFilePath = myDir + "output.tiff";
//Create an instance of TiffOptions and set its various properties
TiffOptions options = new TiffOptions();
options.BitsPerSample = new ushort[] { 8, 8, 8 };
options.Photometric = TiffPhotometrics.Rgb;
options.Xresolution = new TiffRational(72);
options.Yresolution = new TiffRational(72);
options.ResolutionUnit = TiffResolutionUnits.Inch;
options.PlanarConfiguration = TiffPlanarConfigs.Contiguous;
//Set the Compression to AdobeDeflate
options.Compression = TiffCompressions.AdobeDeflate;
//Or Deflate
//options.Compression = TiffCompressions.Deflate;
//Load an existing image in an instance of RasterImage
using (RasterImage image = (RasterImage)Image.Load(sourceFilePath))
{
//Create a new TiffImage from the RasterImage
using (TiffImage tiffImage = new TiffImage(new TiffFrame(image)))
{
//Save the resultant image while passing the instance of TiffOptions
tiffImage.Save(destinationFilePath, options);
}
}
//[VB.NET Code Sample]
Dim sourceFilePath As String = myDir & "sample.bmp"
Dim destinationFilePath As String = myDir & "output.tiff"
'Create an instance of TiffOptions and set its various properties
Dim options As New TiffOptions()
options.BitsPerSample = New UShort() { 8, 8, 8 }
options.Photometric = TiffPhotometrics.Rgb
options.Xresolution = New TiffRational(72)
options.Yresolution = New TiffRational(72)
options.ResolutionUnit = TiffResolutionUnits.Inch
options.PlanarConfiguration = TiffPlanarConfigs.Contiguous
'Set the Compression to AdobeDeflate
options.Compression = TiffCompressions.AdobeDeflate
'Or Deflate
'options.Compression = TiffCompressions.Deflate;
'Load an existing image in an instance of RasterImage
Using image As RasterImage = CType(Image.Load(sourceFilePath), RasterImage)
'Create a new TiffImage from the RasterImage
Using tiffImage As New TiffImage(New TiffFrame(image))
'Save the resultant image while passing the instance of TiffOptions
tiffImage.Save(destinationFilePath, options)
End Using
End Using
//Creating TIFF Image with Deflate/Adobe Deflate Compression
//[C# Code Sample]
string destinationFilePath = myDir + "output.tiff";
//Create an instance of TiffOptions and set its various properties
TiffOptions options = new TiffOptions();
options.BitsPerSample = new ushort[] { 8, 8, 8 };
options.Photometric = TiffPhotometrics.Rgb;
options.Xresolution = new TiffRational(72);
options.Yresolution = new TiffRational(72);
options.ResolutionUnit = TiffResolutionUnits.Inch;
options.PlanarConfiguration = TiffPlanarConfigs.Contiguous;
//Set the Compression to AdobeDeflate
options.Compression = TiffCompressions.AdobeDeflate;
//Or Deflate
//options.Compression = TiffCompressions.Deflate;
//Create a new TiffImage with specific size and TiffOptions settings
using (TiffImage tiffImage = new TiffImage(new TiffFrame(options, 100, 100)))
{
//Loop over the pixels to set the color to red
for (int i = 0; i < 100; i++)
{
tiffImage.ActiveFrame.SetPixel(i, i, Color.Red);
}
//Save resultant image
tiffImage.Save(destinationFilePath);
}
//[VB.NET Code Sample]
Dim destinationFilePath As String = myDir & "output.tiff"
'Create an instance of TiffOptions and set its various properties
Dim options As New TiffOptions()
options.BitsPerSample = New UShort() { 8, 8, 8 }
options.Photometric = TiffPhotometrics.Rgb
options.Xresolution = New TiffRational(72)
options.Yresolution = New TiffRational(72)
options.ResolutionUnit = TiffResolutionUnits.Inch
options.PlanarConfiguration = TiffPlanarConfigs.Contiguous
'Set the Compression to AdobeDeflate
options.Compression = TiffCompressions.AdobeDeflate
'Or Deflate
'options.Compression = TiffCompressions.Deflate;
'Create a new TiffImage with specific size and TiffOptions settings
Using tiffImage As New TiffImage(New TiffFrame(options, 100, 100))
'Loop over the pixels to set the color to red
For i As Integer = 0 To 99
tiffImage.ActiveFrame.SetPixel(i, i, Color.Red)
Next i
'Save resultant image
tiffImage.Save(destinationFilePath)
End Using
//Loading TIFF with Deflate/Adobe Deflate Compression
//[C# Code Sample]
string filePath = "TIFF-Compression-Deflate.tif";
using (TiffImage tiffImage = (TiffImage)Image.Load(filePath))
{
// do processing
}
//[VB.NET Code Sample]
Dim filePath As String = "TIFF-Compression-Deflate.tif"
Using tiffImage As TiffImage = CType(Image.Load(filePath), TiffImage)
' do processing
End Using
Url: http://www.aspose.com/.net/imaging-component.aspx
Language: C# | User: Sheraz Khan | Created: Oct 1, 2014 | Tags: Save Raster Image as TIFF create TIFF with Adobe Deflate Compression Load TIFF Adobe Deflate Compression Create TIFF Image with Deflate Compression .NET Imaging API Concatenate TIFF images