TIFF is a tag based file format which is designed to promote the interchange of digital image data. The general scenario TIFF format was invented for assumes that scanning or painting software creates a TIFF file, which can then be read and incorporated into a document or a publication by an application such as a desktop publishing package.
This image format is rather versatile and have a lot of modifications. Graphics Mill for .NET supports the following compression methods and special-interest formats:
TIFF
image/tiff
*.tiff, *.tif
Description | Read | Write |
---|---|---|
1 bit palette-based | Yes | Yes |
4 bit palette-based | Yes | Yes |
8 bit palette-based | Yes | Yes |
8 bit grayscale | Yes | Yes |
16 bit grayscale with the alpha channel | Yes | Yes |
16 bit grayscale (16 bits per channel) | Yes | Yes |
24 bit RGB | Yes | Yes |
32 bit RGB with the alpha channel | Yes | Yes |
48 bit RGB (16 bits per channel) | Yes | Yes |
64 bit RGB with the alpha channel (16 bits per channel) | Yes | Yes |
32 bit CMYK | Yes | Yes |
40 bit CMYK with the alpha channel | Yes | Yes |
64 bit CMYK (16 bits per channel) | Yes | Yes |
80 bit CMYK with alpha channel (16 bits per channel) | Yes | Yes |
24 bit YCbCr | Yes | No |
Name | Comments |
---|---|
TiffReader.Exif | EXIF data collection. |
TiffReader.Iptc | IPTC data collection. |
TiffReader.Xmp | XML code containing the XMP metadata. |
TiffReader.AdobeResources | Adobe® image resource blocks. |
Name | Default Value | Comments |
---|---|---|
TiffEncoderOptions.Exif
TiffWriter.Exif |
N/A |
EXIF data collection you want to write into the file. |
TiffEncoderOptions.Iptc
TiffWriter.Iptc |
N/A |
IPTC data collection you want to write into the file. |
TiffEncoderOptions.Xmp
TiffWriter.Xmp |
N/A | XML code containing the XMP metadata you want to write into the file. |
TiffEncoderOptions.AdobeResources
TiffWriter.AdobeResources |
N/A | Adobe® image resource blocks you want to write into the file. |
TiffEncoderOptions.Compression
TiffFrame.Compression |
CompressionType.None |
TIFF compression type. |
TiffEncoderOptions.Quality
TiffFrame.Quality |
75 | JPEG quality if compression type is set to CompressionType.Jpeg. |
The simplest way to the TIFF file which has only one frame (or if you do not care about the rest frames) is to pass its name to the constructor:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.tif")
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.tif");
Alternatively, if you already have an instance of the Bitmap, you can use Load method:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap bitmap.Load("c:\Mountain.tif")
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(); bitmap.Load(@"c:\Mountain.tif");
This code example demonstrates how to save the TIFF with the single frame. It just converts the JPEG file into the TIFF format.
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg") bitmap.Save("C:\Mountain.tif", _ New Aurigma.GraphicsMill.Codecs.TiffEncoderOptions(50)) bitmap.Dispose()
using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg")) { bitmap.Save(@"C:\Mountain.tif", new Aurigma.GraphicsMill.Codecs.TiffEncoderOptions(50)); }
Also you can use TiffWriter class instead of the Save method of the Bitmap. In particular it enables you to save the image asynchronously.
The TiffWriter class usage is demonstrated below:
Dim dir As String = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\" Dim images As String() = {"Blue hills.jpg", "Sunset.jpg", "Water lilies.jpg", "Winter.jpg"} Dim bitmap As New Aurigma.GraphicsMill.Bitmap Dim writer As New Aurigma.GraphicsMill.Codecs.TiffWriter("C:\multipage.tif") For Each image As String In images bitmap.Load(dir & image) Dim frame As New Aurigma.GraphicsMill.Codecs.TiffFrame frame.Compression = Aurigma.GraphicsMill.Codecs.CompressionType.Lzw frame.SetBitmap(bitmap) writer.AddFrame(frame) frame.Dispose() Next bitmap.Dispose() writer.Dispose()
string dir = @"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\"; String[] images = {"Blue hills.jpg", "Sunset.jpg", "Water lilies.jpg", "Winter.jpg"}; using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap()) { using(Aurigma.GraphicsMill.Codecs.TiffWriter writer = new Aurigma.GraphicsMill.Codecs.TiffWriter(@"C:\multipage.tif")) { foreach (string image in images) { bitmap.Load(dir + image); using (Aurigma.GraphicsMill.Codecs.TiffFrame frame = new Aurigma.GraphicsMill.Codecs.TiffFrame()) { frame.Compression = Aurigma.GraphicsMill.Codecs.CompressionType.Lzw; frame.SetBitmap(bitmap); writer.AddFrame(frame); } } } }
To load the TIFF files that contains multiple frames, you should use a TiffReader class. The code below demonstrates its usage. It reads multipage TIFF file and save each page into the separate JPEG file.
Dim filename As String = "c:\multipage.tif" Dim reader As Aurigma.GraphicsMill.Codecs.FormatReader = _ Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader(filename) Dim bitmap As New Aurigma.GraphicsMill.Bitmap For i As Integer = 0 To reader.FrameCount - 1 Dim frame As Aurigma.GraphicsMill.Codecs.Frame = reader.LoadFrame(i) frame.GetBitmap(bitmap) frame.Dispose() bitmap.Save("c:\frame_" & i & ".jpg") Next bitmap.Dispose() reader.Dispose()
string filename = @"c:\multipage.tif"; using (Aurigma.GraphicsMill.Codecs.IFormatReader reader = Aurigma.GraphicsMill.Codecs.FormatManager.CreateFormatReader(filename)) { using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap()) { for (int i = 0; i < reader.FrameCount - 1; i++) { using (Aurigma.GraphicsMill.Codecs.IFrame frame = reader.LoadFrame(i)) { frame.GetBitmap(bitmap); bitmap.Save(@"c:\frame_" + i.ToString() + ".jpg"); } } } }
TIFF files can store EXIF, IPTC, XMP, and Adobe® image resource blocks metadata collections. Graphics Mill for .NET enables you to extract this data from the TIFF file and save it into another TIFF file (as well as into the other file format which supports such kinds of metadata). This code example demonstrates how to add metadata to the file:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg") Dim encoderOptions As New Aurigma.GraphicsMill.Codecs.TiffEncoderOptions(50) 'EXIF Dim exif As New Aurigma.GraphicsMill.Codecs.ExifDictionary exif(Aurigma.GraphicsMill.Codecs.ExifDictionary.Software) = "Aurigma Graphics Mill" encoderOptions.Exif = exif 'IPTC Dim iptc As New Aurigma.GraphicsMill.Codecs.IptcDictionary iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Category) = "Nature" iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice) = "Aurigma Inc." iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword) = "mountain" encoderOptions.Iptc = iptc 'Adobe resource blocks Dim adobeResources As New Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary 'Create new adobe image resource block with the required metadata Dim arBlock As New Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", New Byte() {1}) 'Set this block to the item with 0x040A ID (copyright flag) adobeResources.Item(&H40A) = arBlock encoderOptions.AdobeResources = adobeResources 'XMP Dim xmp As New Aurigma.GraphicsMill.Codecs.XmpData() 'Create a node with the required metadata Dim node As New Aurigma.GraphicsMill.Codecs.XmpValueNode( _ Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, _ "John Doe", _ Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator) xmp.AddNode(node) encoderOptions.Xmp = xmp.Save() bitmap.Save("C:\Mountain.tif", encoderOptions) bitmap.Dispose()
using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg")) { Aurigma.GraphicsMill.Codecs.TiffEncoderOptions encoderOptions = new Aurigma.GraphicsMill.Codecs.TiffEncoderOptions(50); //EXIF Aurigma.GraphicsMill.Codecs.ExifDictionary exif = new Aurigma.GraphicsMill.Codecs.ExifDictionary(); exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill"; encoderOptions.Exif = exif; //IPTC Aurigma.GraphicsMill.Codecs.IptcDictionary iptc = new Aurigma.GraphicsMill.Codecs.IptcDictionary(); iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature"; iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = "Aurigma Inc."; iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain"; encoderOptions.Iptc = iptc; //Adobe resource blocks Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary adobeResources = new Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary(); //Create new adobe image resource block with the required metadata Aurigma.GraphicsMill.Codecs.AdobeResourceBlock arBlock = new Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", new byte[] { 1 }); //Set this block to the item with 0x040A ID (copyright flag) adobeResources[0x040A] = arBlock; encoderOptions.AdobeResources = adobeResources; //XMP Aurigma.GraphicsMill.Codecs.XmpData xmp = new Aurigma.GraphicsMill.Codecs.XmpData(); //Create a node with the required metadata Aurigma.GraphicsMill.Codecs.XmpValueNode node = new Aurigma.GraphicsMill.Codecs.XmpValueNode( Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, "John Doe", Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator); xmp.AddNode(node); encoderOptions.Xmp = xmp.Save(); bitmap.Save(@"C:\Mountain.tif", encoderOptions); }
The code below does the same, but using TiffWriter class:
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg") Dim writer As New Aurigma.GraphicsMill.Codecs.TiffWriter("C:\Mountain.tif") 'EXIF Dim exif As New Aurigma.GraphicsMill.Codecs.ExifDictionary exif(Aurigma.GraphicsMill.Codecs.ExifDictionary.Software) = "Aurigma Graphics Mill" writer.Exif = exif 'IPTC Dim iptc As New Aurigma.GraphicsMill.Codecs.IptcDictionary iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Category) = "Nature" iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice) = "Aurigma Inc." iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword) = "mountain" writer.Iptc = iptc 'Adobe resource blocks Dim adobeResources As New Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary 'Create new adobe image resource block with the required metadata Dim arBlock As New Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", New Byte() {1}) 'Set this block to the item with 0x040A ID (copyright flag) adobeResources.Item(&H40A) = arBlock writer.AdobeResources = adobeResources 'XMP Dim xmp As New Aurigma.GraphicsMill.Codecs.XmpData() 'Create a node with the required metadata Dim node As New Aurigma.GraphicsMill.Codecs.XmpValueNode( _ Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, _ "John Doe", _ Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator) xmp.AddNode(node) writer.Xmp = xmp.Save() Dim frame As New Aurigma.GraphicsMill.Codecs.TiffFrame(50) frame.SetBitmap(bitmap) bitmap.Dispose() writer.AddFrame(frame) frame.Dispose() writer.Dispose()
using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg")) { using (Aurigma.GraphicsMill.Codecs.TiffWriter writer = new Aurigma.GraphicsMill.Codecs.TiffWriter(@"C:\Mountain.tif")) { //EXIF Aurigma.GraphicsMill.Codecs.ExifDictionary exif = new Aurigma.GraphicsMill.Codecs.ExifDictionary(); exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill"; writer.Exif = exif; //IPTC Aurigma.GraphicsMill.Codecs.IptcDictionary iptc = new Aurigma.GraphicsMill.Codecs.IptcDictionary(); iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature"; iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = "Aurigma Inc."; iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain"; writer.Iptc = iptc; //Adobe resource blocks Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary adobeResources = new Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary(); //Create new adobe image resource block with the required metadata Aurigma.GraphicsMill.Codecs.AdobeResourceBlock arBlock = new Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", new byte[] { 1 }); //Set this block to the item with 0x040A ID (copyright flag) adobeResources[0x040A] = arBlock; writer.AdobeResources = adobeResources; //XMP Aurigma.GraphicsMill.Codecs.XmpData xmp = new Aurigma.GraphicsMill.Codecs.XmpData(); //Create a node with the required metadata Aurigma.GraphicsMill.Codecs.XmpValueNode node = new Aurigma.GraphicsMill.Codecs.XmpValueNode( Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, "John Doe", Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator); xmp.AddNode(node); writer.Xmp = xmp.Save(); using (Aurigma.GraphicsMill.Codecs.TiffFrame frame = new Aurigma.GraphicsMill.Codecs.TiffFrame(50)) { frame.SetBitmap(bitmap); writer.AddFrame(frame); } } }