ImageGear PDF v25.1 - Updated
Initializing Assemblies
User Guide > How to Work with... > Initializing Assemblies

ImageGear assemblies require explicit initialization at application startup.

Common File Formats

Assembly: ImageGear.Formats.Common.dll

Supported Formats: BMPCLPCURGIFJPEGPNGTIFF

C#
Copy Code
using ImageGear.Core;
using ImageGear.Formats;
public void ApplicationStartupMethod()
{
     // License scope.

     // Initialize assemblies following the order recommended.
     ImGearCommonFormats.Initialize();
}
VB.NET
Copy Code
Imports ImageGear.Core
Imports ImageGear.Formats
Public Sub ApplicationStartupMethod()
            ' License scope.

            ' Initialize assemblies following the order recommended.
            ImGearCommonFormats.Initialize()
End Sub

The Common File Formats component additionally provides two alternative file format implementations for JPEG and PNG. These file filters are based on native binary code which is unlike the default filters implemented on .NET.

ImGearCommonFormats.Initialize() method initializes the file filter list with default JPEG and PNG filters. Update the filter list using ImGearFileFilters.Set(IImGearFormat format) method, which should be called after initialization to replace the default filters with native.

C#
Copy Code
using ImageGear.Core;
using ImageGear.Formats;
public void ApplicationStartupMethod()
{
     // License scope.
 
     // Initialize filter list with default set of common file formats.
     ImGearCommonFormats.Initialize();
   
    // Replace default (managed) JPEG and PNG file formats with native implementation.
    ImGearFileFormats.Filters.Set(ImGearCommonFormats.CreateJpegFormat());
    ImGearFileFormats.Filters.Set(ImGearCommonFormats.CreatePngFormat());
 
}
VB.NET
Copy Code
Imports ImageGear.Core
Imports ImageGear.Formats

Public Sub ApplicationStartupMethod()
    ' License scope.

    ' Initialize filter list with default set of common file formats.
    ImGearCommonFormats.Initialize()

    ‘ Replace default (managed) JPEG and PNG file formats with native implementation.
    ImGearFileFormats.Filters.Set(ImGearCommonFormats.CreateJpegFormat())
    ImGearFileFormats.Filters.Set(ImGearCommonFormats.CreatePngFormat())

End Sub

PDF and PS Formats

Assembly: ImageGear.Formats.Pdf.dll

This assembly requires both initialization and termination. Furthermore, the ImGearPDF.Initialize method does not add PDF and PostScript formats to the global format filter list. PDF and PostScript formats should be added explicitly .

C#
Copy Code
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.Formats.PDF;
public void ApplicationStartupMethod()
{
     // License scope.

     // Initialize assemblies following the order recommended.
     ImGearPDF.Initialize();
}

public void ApplicationEndPoint()
{
     // Terminate PDF Formats.
     ImGearPDF.Terminate();
}
VB.NET
Copy Code
Imports ImageGear.Core
Imports ImageGear.Formats
Public Sub ApplicationStartupMethod()
            ' License scope.

            ' Initialize assemblies following the order recommended.
            ImGearPDF.Initialize()
End Sub

Public Sub ApplicationEndPoint()
            ' Terminate PDF Formats.
            ImGearPDF.Terminate()
End Sub

Global and Local Initialization

After initializing ImageGear format filters, we can specify filter control parameters. Many format filters in ImageGear have control parameters that affect filter operations, such as image reading and writing. Those parameters may be declared by the format specification, or they may be specific to the format implementation by ImageGear. There are two ways to specify filter control parameters:

Specify Parameters Globally

This affects all format reading and writing operations, and threads in the process. Use the Filters static property of the ImGearFileFormats class to set parameters globally:

C#
Copy Code
IImGearFormat jpgFormat = ImGearFileFormats.Filters.Get(ImGearFormats.JPG);
ImGearControlParameter Param = jpgFormat.Parameters.GetByName("SaveType");
// Lossless.
Param.Value = 1;
VB.NET
Copy Code
Dim jpgFormat As IImGearFormat = ImGearFileFormats.Filters.[Get](ImGearFormats.JPG)
Dim Param As ImGearControlParameter = jpgFormat.Parameters.GetByName("SaveType")
' Lossless.
Param.Value = 1

Specify Parameters Locally

This affects only one reading or writing operation, and thus can be used for setting different parameters in different threads. To specify local parameters, create an instance of ImGearFileFilters class, assign it to ImGearLoadOptions.Filters property or ImGearSaveOptions.Filters property, and pass the Load or Save options object to the reading or writing method, correspondingly:

C#
Copy Code
ImGearFileFilters localFilters = new ImGearFileFilters();
IImGearFormat jpgFormat = localFilters.Get(ImGearFormats.JPG);
ImGearControlParameter controlParam = jpgFormat.Parameters.GetByName("SaveType");
// Lossless.
controlParam .Value = 1;
ImGearSaveOptions SaveOptions = new ImGearSaveOptions();
SaveOptions.Filters = localFilters;
VB.NET
Copy Code
Dim localFilters As New ImGearFileFilters()
Dim jpgFormat As IImGearFormat = localFilters.[Get](ImGearFormats.JPG)
Dim controlParam As ImGearControlParameter = jpgFormat.Parameters.GetByName("SaveType")
' Lossless.
controlParam.Value = 1
Dim SaveOptions As New ImGearSaveOptions()
SaveOptions.Filters = localFilters