ImageGear assemblies require explicit initialization at application startup.
Initialization Required Ordering
The order in which these assemblies are initialized is important, because it defines format detection priority. The following order is recommended when initializing the assemblies needed in your application startup to ensure proper detection:
Common File Formats
Assembly: ImageGear.Core.dll
Supported Formats: BMP, CLP, CUR, DIB, GIF, JFIF, JPEG, PNG, RAW, SVG, TIFF
ImGearCommonFormats.Initialize() method initializes the file filter list with default JPEG and PNG filters.
C#
using ImageGear.Core;
using ImageGear.Formats;
public void ApplicationStartupMethod()
{
// License scope.
// Initialize assemblies following the order recommended.
ImGearCommonFormats.Initialize();
}
VB.NET
Imports ImageGear.Core
Imports ImageGear.Formats
Public Sub ApplicationStartupMethod()
' License scope.
' Initialize assemblies following the order recommended.
ImGearCommonFormats.Initialize()
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 before initialization, see PDF and PS in the "Additional Support" section, below.
C#
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
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
Additional Support
The following ImageGear components also need to be explicitly added at application startup if required. The goal is to load the ImageGear capabilities for working with a specific set of formats that your application aims to process and that are not included in the assemblies initialized.
Before adding any of these components, you need to have at least initialized Common Formats.
PDF and PS
Namespace: ImageGear.Formats.PDF
C#
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.Formats.PDF;
public void ApplicationStartupMethod()
{
// License scope.
// Initialize assemblies following the order recommended.
// Require at least Common Formats.
ImGearCommonFormats.Initialize();
// Add support for PDF and PS
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePDFFormat());
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePSFormat());
// Require PDF Formats.
ImGearPDF.Initialize();
}
VB.NET
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.Formats.PDF
Public Sub ApplicationStartupMethod()
' License scope.
' Initialize assemblies following the order recommended.
' Require at least Common Formats.
ImGearCommonFormats.Initialize()
' Require PDF Formats.
ImGearPDF.Initialize()
' Add support for PDF and PS
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePDFFormat())
ImGearFileFormats.Filters.Add(ImGearPDF.CreatePSFormat())
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#
IImGearFormat jpgFormat = ImGearFileFormats.Filters.Get(ImGearFormats.JPG);
ImGearControlParameter Param = jpgFormat.Parameters.GetByName("SaveType");
// Lossless.
Param.Value = 1;
VB.NET
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#
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
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