Class TImageFormatManager

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TImageFormatManager = class(TCustomImageFormatManager)

Description

General-purpose Image Format Manager that has pluggable mechanism so that handlers (those derived from TCustomImageFormatHandler class) can be associated with it to load and save different image formats. If multiple handlers that support the same image format are associated, then the one that was most recently associated will be used.

Hierarchy

Overview

Methods

Public function IndexOfHandler(const ImageFormatHandler: TCustomImageFormatHandler): Integer;
Public function LoadFromAsset(const AssetName: StdString; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;
Public function LoadFromFile(const FileName: StdString; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;
Public function LoadFromStream(const Extension: StdString; const Stream: TStream; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;
Public function RegisterExtension(const Extension: StdString; const Handler: TCustomImageFormatHandler; const Context: Pointer): Boolean;
Public function RegisterHandler(const ImageFormatHandler: TCustomImageFormatHandler): Integer;
Public function SaveToFile(const FileName: StdString; const SourceSurface: TPixelSurface; const Quality: Pointer = nil): Boolean; override;
Public function SaveToStream(const Extension: StdString; const Stream: TStream; const SourceSurface: TPixelSurface; const Quality: Pointer = nil): Boolean; override;
Public function UnregisterExtension(const Extension: StdString; const Handler: TCustomImageFormatHandler = nil): Boolean;
Public procedure Clear;
Public procedure UnregisterHandler(const ImageFormatHandler: TCustomImageFormatHandler);

Description

Methods

Public function IndexOfHandler(const ImageFormatHandler: TCustomImageFormatHandler): Integer;

Returns index (or the first occurrence) of the specified image format handler that is associated with this class.

Public function LoadFromAsset(const AssetName: StdString; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;

Loads image from specified file located in /assets sub-folder. This function will look through the internal registry and use one of the most recently registered handlers that supports such extension. If no handler supports such extension, the method will fail. This function only works on Android platform.

Parameters
FileName
A valid file name (with extension) that represents the image.
DestSurface
The destination surface where image data will be saved. It does need to be a valid instance of TPixelSurface, but it may or may not be empty.
AlphaFormatRequest
The preference for premultipled or non-premultiplied alpha that should be used while loading the image. This is just a suggestion for the manager and it may or may not be followed depending on platform implementation.
Returns

True when successful or False otherwise.

Public function LoadFromFile(const FileName: StdString; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;

Loads image from specified file. This function will look through the internal registry and use one of the most recently registered handlers that supports such extension. If no handler supports such extension, the method will fail.

Parameters
FileName
A valid file name (with extension) that includes full path that represents the image.
DestSurface
The destination surface where image data will be saved. It does need to be a valid instance of TPixelSurface, but it may or may not be empty.
AlphaFormatRequest
The preference for premultipled or non-premultiplied alpha that should be used while loading the image. This is just a suggestion for the manager and it may or may not be followed depending on platform implementation.
Returns

True when successful or False otherwise.

Public function LoadFromStream(const Extension: StdString; const Stream: TStream; const DestSurface: TPixelSurface; const AlphaFormatRequest: TAlphaFormatRequest = TAlphaFormatRequest.DontCare): Boolean; override;

Loads image from specified stream. This function will look through the internal registry and use one of the most recently registered handlers that supports such extension. If no handler supports such extension, the method will fail.

Parameters
Extension
Extension (including dot, e.g. ".png") that represents the format in which the image is stored in the stream.
Stream
Stream which will be used for reading the image from. The current position of the stream will be used and after the call it will be adjusted to be right at the end of image data.
DestSurface
The destination surface where image data will be saved. It does need to be a valid instance of TPixelSurface, but it may or may not be empty.
AlphaFormatRequest
The preference for premultipled or non-premultiplied alpha that should be used while loading the image. This is just a suggestion for the manager and it may or may not be followed depending on platform implementation.
Returns

True when successful or False otherwise.

Public function RegisterExtension(const Extension: StdString; const Handler: TCustomImageFormatHandler; const Context: Pointer): Boolean;

Registers the specified image format handler (that was previously associated by using RegisterHandler call, to the specified extension. If multiple handlers are registered to the same extension, then the handler that was most recently registered will be used. Context parameter will be saved and then passed to the appropriate methods inside TCustomImageFormatHandler class when loading and saving images.

Public function RegisterHandler(const ImageFormatHandler: TCustomImageFormatHandler): Integer;

Registers specified image format handler with the manager and returns its index in the list.

Public function SaveToFile(const FileName: StdString; const SourceSurface: TPixelSurface; const Quality: Pointer = nil): Boolean; override;

Saves image to specified file. This function will look through the internal registry and use one of the most recently registered handlers that supports such extension. If no handler supports such extension, the method will fail.

Parameters
FileName
A valid file name (with extension) that includes full path where the image is to be saved. The path to this file must exist.
SourceSurface
The source surface where image data will be taken from. Note that the surface pixel format may determine the format in which the image will be saved. However, since not all pixel formats may be supported, the function may fail. Typically. TPixelFormat.A8R8G8B8 is the most widely supported format and should work under most circumstances.
Quality
Generic parameter that can be used as hint for saved image quality. For instance, for JPEG files, this is typically just an integer number (typecast to Pointer) representing quality between 0 and 100.
Returns

True when successful or False otherwise.

Public function SaveToStream(const Extension: StdString; const Stream: TStream; const SourceSurface: TPixelSurface; const Quality: Pointer = nil): Boolean; override;

Saves image to specified stream. This function will look through the internal registry and use one of the most recently registered handlers that supports such extension. If no handler supports such extension, the method will fail.

Parameters
Extension
Extension (including dot, e.g. ".png") that represents the format in which the image should be stored in the stream.
Stream
Stream which will be used for writing the image to. The current position of the stream will be used and after the call it will be adjusted to be right at the end of image data.
SourceSurface
The source surface where image data will be taken from. Note that the surface pixel format may determine the format in which the image will be saved. However, since not all pixel formats may be supported, the function may fail. Typically. TPixelFormat.A8R8G8B8 is the most widely supported format and should work under most circumstances.
Quality
Generic parameter that can be used as hint for saved image quality. For instance, for JPEG files, this is typically just an integer number (typecast to Pointer) representing quality between 0 and 100.
Returns

True when successful or False otherwise.

Public function UnregisterExtension(const Extension: StdString; const Handler: TCustomImageFormatHandler = nil): Boolean;

Removes the registry for given extension associated with the provided handler. If the handler is not specified, or is Nil, then the first handler that supports such extension will be looked for. True is returned when the method success and False otherwise. If it is necessary to unregister all handlers for specific extension, then t his method should be called multiple times until False is returned.

Public procedure Clear;

Removes all the associations with image format handlers from the list.

Public procedure UnregisterHandler(const ImageFormatHandler: TCustomImageFormatHandler);

Removes specified image format handler from the list that was previously associated with the manager.


Copyright © 2000 - 2017 Yuriy Kotsarenko. Help files generated by PasDoc.