LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

CodecsTiffOptions Class

Example 





Members 
Provides extra options for loading and saving TIFF images. .NET support WinRT support Silverlight support
Object Model
CodecsTiffOptions ClassCodecsTiffLoadOptions ClassCodecsTiffSaveOptions Class
Syntax
public class CodecsTiffOptions 
'Declaration
 
Public Class CodecsTiffOptions 
'Usage
 
Dim instance As CodecsTiffOptions
public sealed class CodecsTiffOptions 
function Leadtools.Codecs.CodecsTiffOptions()
public ref class CodecsTiffOptions 
Example
 
Public Sub CodecsTiffOptionsExample()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "OCR1.TIF")

      ' Get all Information about the Tiff file that you want to load.
      Dim imageInfo As CodecsImageInfo = codecs.GetInformation(srcFileName, True)

      If imageInfo.Tiff.IsImageFileDirectoryOffsetValid Then
         codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset
         codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset
      End If

      codecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid
      codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid

      codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = True

      Dim image As RasterImage = codecs.Load(srcFileName)

      codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette
      codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette

      'Set the tiffSave options
      codecs.Options.Tiff.Save.NoPageNumber = False
      codecs.Options.Tiff.Save.NoSubFileType = False
      codecs.Options.Tiff.Save.UsePhotometricInterpretation = True
      codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr
      codecs.Options.Tiff.Save.UseTileSize = True
      codecs.Options.Tiff.Save.TileHeight = 200
      codecs.Options.Tiff.Save.TileWidth = 200

      'saving the image
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff1.TIF"), RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

      'change some tiffsave options.
      codecs.Options.Tiff.Save.NoPageNumber = True
      codecs.Options.Tiff.Save.NoSubFileType = True
      codecs.Options.Tiff.Save.UsePhotometricInterpretation = False
      codecs.Options.Tiff.Save.UseTileSize = False
      codecs.Options.Tiff.Save.NoPalette = False
      codecs.Options.Tiff.Save.PreservePalette = True
      codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette

      'save the image with different name.
      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff2.TIF"), RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

      ' Clean up
      image.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void CodecsTiffOptionsExample()
     {
         RasterCodecs codecs = new RasterCodecs();

         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "OCR1.TIF");

         // Get all Information about the Tiff file that you want to load.
         CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, true);

         if (imageInfo.Tiff.IsImageFileDirectoryOffsetValid)
         {
             codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
             codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
         }

         codecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;
         codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;

         codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = true;

         RasterImage image = codecs.Load(srcFileName);

         codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette;
         codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette;

         //Set the tiffSave options
         codecs.Options.Tiff.Save.NoPageNumber = false;
         codecs.Options.Tiff.Save.NoSubFileType = false;
         codecs.Options.Tiff.Save.UsePhotometricInterpretation = true;
         codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr;
         codecs.Options.Tiff.Save.UseTileSize = true;
         codecs.Options.Tiff.Save.TileHeight = 200;
         codecs.Options.Tiff.Save.TileWidth = 200;

         //saving the image
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff1.TIF"), RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

         //change some tiffsave options.
         codecs.Options.Tiff.Save.NoPageNumber = true;
         codecs.Options.Tiff.Save.NoSubFileType = true;
         codecs.Options.Tiff.Save.UsePhotometricInterpretation = false;
         codecs.Options.Tiff.Save.UseTileSize = false;
         codecs.Options.Tiff.Save.NoPalette = false;
         codecs.Options.Tiff.Save.PreservePalette = true;
         codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette;

         //save the image with different name.
         codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "testtiff2.TIF"), RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

         // Clean up
         image.Dispose();
         codecs.Dispose();
     }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsTiffOptionsExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         // Load the image
         var srcFileName = "Assets\\OCR1.tif";
         var imageInfo;
         var image;
         // Get all Information about the Tiff file that you want to load.
         return Tools.AppInstallFolder().getFileAsync(srcFileName)
         .then(function (loadFile) {
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), true, 1)
         })
         .then(function (imgInfo) {
            imageInfo = imgInfo;

            if (imageInfo.tiff.isImageFileDirectoryOffsetValid) {
               codecs.options.tiff.load.imageFileDirectoryOffset = imageInfo.tiff.imageFileDirectoryOffset;
               codecs.options.tiff.save.imageFileDirectoryOffset = imageInfo.tiff.imageFileDirectoryOffset;
            }

            codecs.options.tiff.load.useImageFileDirectoryOffset = imageInfo.tiff.isImageFileDirectoryOffsetValid;
            codecs.options.tiff.save.useImageFileDirectoryOffset = imageInfo.tiff.isImageFileDirectoryOffsetValid;

            codecs.options.tiff.load.ignorePhotometricInterpretation = true;

            // Load the image
            return Tools.AppInstallFolder().getFileAsync(srcFileName)
         })
         .then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) {
            image = img;

            codecs.options.tiff.save.noPalette = imageInfo.tiff.hasNoPalette;
            codecs.options.tiff.save.preservePalette = imageInfo.tiff.hasNoPalette;

            //Set the tiffSave options
            codecs.options.tiff.save.noPageNumber = false;
            codecs.options.tiff.save.noSubFileType = false;
            codecs.options.tiff.save.usePhotometricInterpretation = true;
            codecs.options.tiff.save.photometricInterpretation = CodecsTiffPhotometricInterpretation.ycbCr;
            codecs.options.tiff.save.useTileSize = true;
            codecs.options.tiff.save.tileHeight = 200;
            codecs.options.tiff.save.tileWidth = 200;

            //saving the image
            var destFileName = "testtiff1.TIF";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, image.bitsPerPixel, 1, image.pageCount, 1, CodecsSavePageMode.overwrite)
         })
         .then(function () {

            //change some tiffsave options.
            codecs.options.tiff.save.noPageNumber = true;
            codecs.options.tiff.save.noSubFileType = true;
            codecs.options.tiff.save.usePhotometricInterpretation = false;
            codecs.options.tiff.save.useTileSize = false;
            codecs.options.tiff.save.noPalette = false;
            codecs.options.tiff.save.preservePalette = true;
            codecs.options.tiff.save.photometricInterpretation = CodecsTiffPhotometricInterpretation.palette;

            //save the image with different name.
            destFileName = "testtiff2.TIF";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.ccittGroup4, image.bitsPerPixel, 1, image.pageCount, 1, CodecsSavePageMode.overwrite)
         })
         .then(function () {
            // Clean up
            image.close();
            codecs.close();
         });
      }
   }
}
[TestMethod]
public async Task CodecsTiffOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load the image
   string srcFileName = @"Assets\OCR1.tif";

   // Get all Information about the Tiff file that you want to load.
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1);

   if (imageInfo.Tiff.IsImageFileDirectoryOffsetValid)
   {
      codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
      codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
   }

   codecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;
   codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;

   codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = true;

   // Load the image
   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette;
   codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette;

   //Set the tiffSave options
   codecs.Options.Tiff.Save.NoPageNumber = false;
   codecs.Options.Tiff.Save.NoSubFileType = false;
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = true;
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr;
   codecs.Options.Tiff.Save.UseTileSize = true;
   codecs.Options.Tiff.Save.TileHeight = 200;
   codecs.Options.Tiff.Save.TileWidth = 200;

   //saving the image
   string destFileName = @"testtiff1.TIF";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

   //change some tiffsave options.
   codecs.Options.Tiff.Save.NoPageNumber = true;
   codecs.Options.Tiff.Save.NoSubFileType = true;
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = false;
   codecs.Options.Tiff.Save.UseTileSize = false;
   codecs.Options.Tiff.Save.NoPalette = false;
   codecs.Options.Tiff.Save.PreservePalette = true;
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette;

   //save the image with different name.
   destFileName = @"testtiff2.TIF";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
public void CodecsTiffOptionsExample(Stream inStreamTif, Stream outStreamTif, Stream outStreamCcittG4)
{
   RasterCodecs codecs = new RasterCodecs();
   // Get all Information about the Tiff file that you want to load.
   CodecsImageInfo imageInfo = codecs.GetInformation(inStreamTif, true);

   if (imageInfo.Tiff.IsImageFileDirectoryOffsetValid)
   {
      codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
      codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset;
   }

   codecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;
   codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid;

   codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = true;

   RasterImage image = codecs.Load(inStreamTif);

   codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette;
   codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette;

   //Set the tiffSave options
   codecs.Options.Tiff.Save.NoPageNumber = false;
   codecs.Options.Tiff.Save.NoSubFileType = false;
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = true;
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr;
   codecs.Options.Tiff.Save.UseTileSize = true;
   codecs.Options.Tiff.Save.TileHeight = 200;
   codecs.Options.Tiff.Save.TileWidth = 200;

   //saving the image
   codecs.Save(image, outStreamTif, RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

   //change some tiffsave options.
   codecs.Options.Tiff.Save.NoPageNumber = true;
   codecs.Options.Tiff.Save.NoSubFileType = true;
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = false;
   codecs.Options.Tiff.Save.UseTileSize = false;
   codecs.Options.Tiff.Save.NoPalette = false;
   codecs.Options.Tiff.Save.PreservePalette = true;
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette;

   //save the image with different name.
   codecs.Save(image, outStreamCcittG4, RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);

   // Clean up
   image.Dispose();
}
Public Sub CodecsTiffOptionsExample(ByVal inStreamTif As Stream, ByVal outStreamTif As Stream, ByVal outStreamCcittG4 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Get all Information about the Tiff file that you want to load.
   Dim imageInfo As CodecsImageInfo = codecs.GetInformation(inStreamTif, True)

   If imageInfo.Tiff.IsImageFileDirectoryOffsetValid Then
      codecs.Options.Tiff.Load.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset
      codecs.Options.Tiff.Save.ImageFileDirectoryOffset = imageInfo.Tiff.ImageFileDirectoryOffset
   End If

   codecs.Options.Tiff.Load.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid
   codecs.Options.Tiff.Save.UseImageFileDirectoryOffset = imageInfo.Tiff.IsImageFileDirectoryOffsetValid

   codecs.Options.Tiff.Load.IgnorePhotometricInterpretation = True

   Dim image As RasterImage = codecs.Load(inStreamTif)

   codecs.Options.Tiff.Save.NoPalette = imageInfo.Tiff.HasNoPalette
   codecs.Options.Tiff.Save.PreservePalette = imageInfo.Tiff.HasNoPalette

   'Set the tiffSave options
   codecs.Options.Tiff.Save.NoPageNumber = False
   codecs.Options.Tiff.Save.NoSubFileType = False
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = True
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.YcbCr
   codecs.Options.Tiff.Save.UseTileSize = True
   codecs.Options.Tiff.Save.TileHeight = 200
   codecs.Options.Tiff.Save.TileWidth = 200

   'saving the image
   codecs.Save(image, outStreamTif, RasterImageFormat.Tif, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

   'change some tiffsave options.
   codecs.Options.Tiff.Save.NoPageNumber = True
   codecs.Options.Tiff.Save.NoSubFileType = True
   codecs.Options.Tiff.Save.UsePhotometricInterpretation = False
   codecs.Options.Tiff.Save.UseTileSize = False
   codecs.Options.Tiff.Save.NoPalette = False
   codecs.Options.Tiff.Save.PreservePalette = True
   codecs.Options.Tiff.Save.PhotometricInterpretation = CodecsTiffPhotometricInterpretation.Palette

   'save the image with different name.
   codecs.Save(image, outStreamCcittG4, RasterImageFormat.CcittGroup4, image.BitsPerPixel, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite)

   ' Clean up
   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CodecsTiffOptions Members
Leadtools.Codecs Namespace

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.