DEV Community

Dmitry Matuzko
Dmitry Matuzko

Posted on

Controlling image loading process in Aspose.Imaging

Aspose.Imaging provides options to control image loading process, so as wether to apply ICC profile or not, or how high error tolerance is allowed. Most options are related to PSD format, but some other image formats have their options as well, and there are some options common for all formats.

Using LoadOptions

Specifying options for image loading process is straightforward: create an instance of LoadOptions class or its descendant for corresponding image format, set up its properties and pass it to Image's Load method. The following example disables default behaviour of processing image raster data with image's embedded ICC profile on loading.

LoadOptions loadOptions = new LoadOptions();
loadOptions.UseIccProfileConversion = false;

using(image = Image.load(sourcePath, loadOptions))
{
    image.save(outputPath, new PngOptions());
}
Enter fullscreen mode Exit fullscreen mode

For format-specific options, just create an instance of corresponding class and be sure you're loading an image of that exact format, otherwise it's the same.

Common loading options

Options that are common for all formats are defined in the base LoadOptions class. There is a total of three availible options:
UseIccProfileConversion - Used to force disable or force enable application of image's embedded ICC profile to image's raster data.
DataBackgroundColor - sets the background color. Background color is typically used for damaged data, when original pixel color can't be recovered.
DataRecoveryMode - sets damage tolerance mode. Either throw exception on any error, or try to recover data while it's consistent and format is not broken, or recover without any checking.

PSD options

PSD, being a complex format, has the most options. In addition to common options, PsdLoadOptions adds next options:
DefaultReplacementFont - the font that will be used to draw text during raster export if the font specified in text layer is not present in system.
IgnoreAlphaChannel - if true, discards aplha data.
IgnoreTextLayerWidthOnUpdate - Whether text layer's fixed width will be ignoring when text is updated when you're working with image.
LoadEffectsResource - Whether effect resources should be loaded. Default is false. If the option is set, only supported effects will be applied anyways.
ReadOnlyMode - When read only mode is set, changes applied to layers will not be saved to final image, all data is used straight from ImageData section, so loaded image is identical to Photoshop.
UseDiskForLoadEffectsResource - By default, effect resources are loaded from disk, if you have enough RAM, you can set it so effect resources will be loaded into memory, thus making processing faster.

PNG options

PngLoadOptions adds StrictMode option, which is an additional error tolerance setting that checks if any of file's critical chunks is truncated. As file can be loaded with some chunks missing, default setting is false.

DNG options

DngLoadOptions adds option to control pre-demosaic denoising as Fbdd property. Either no reduction, light reduction or full reduction.

SVG options

SvgLoadOptions adds DefaultHeight and DefaultWidth properties, which set or get the respective dimensions to which the image is rendered. Should only be used when dimensions are not specified in file.

JPEG2000 options

Jpeg2000 is a relatively complex algorithm and thus decoding can be slow. So MaximumDecodingTime option is present in Jpeg2000LoadOptions to prevent hanging on slower machines on very large - over 5500x6500 pixels - images. Time is specified in seconds.

That's all for now, stay tuned!

For more examples please visit the Aspose.Imaging GitHub page. There's also Twitter and Facebook pages for news on Aspose.Imaging.

Top comments (0)