ImageEn, unit imageenio

TImageEnIO.ImportMetafile

TImageEnIO.ImportMetafile


Declaration

function ImportMetafile(const FileName: WideString; Width: Integer = -1; Height: Integer = -1; MaintainAR: Boolean = False): Boolean; overload;
function ImportMetafile(const FileName: WideString; Width, Height: Integer; WithAlpha: Boolean; BackgroundFill: TColor = clNone; MaintainAR: Boolean = False): Boolean; overload;
function ImportMetafile(Stream: TStream; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True; BackgroundFill: TColor = clNone; MaintainAR: Boolean = False): Boolean; overload;
function ImportMetafile(meta: TMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: Boolean = True; BackgroundFill: TColor = clNone; MaintainAR: Boolean = False): Boolean; overload;
function ImportMetafile(meta: TIEMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: Boolean = True; BackgroundFill: TColor = clNone; MaintainAR: Boolean = False); Boolean; overload;


Description

Imports a WMF or EMF vectorial image. If the file does not represent a valid image format, ImportMetafile raises an EInvalidGraphic exception.

Width and Height specify the image size (the rectangle where the vectorial image will be painted). If -1 is specified for both, the original image size is used.
To maintain the image aspect ratio set only one size, assigning -1 to the other, e.g. ImportMetafile('axi.emf', -1, 500); or set both values and enable MaintainAR.

If WithAlpha is true then ImportMetaFile creates an alpha channel, making only the metafile content visible.
BackgroundFill specifies the fill for the non-content area of the image. If clNone is specified, then EMFBackgroundColor or the Background color is used.

Note:
ImportMetafile converts the vectorial image to a raster image, so you must limit the rasterized image sizes. The maximum allowed size is specified by MaxImageEMFSize and MaxImageEMFMatrixSize
ImportMetafile should not be used in threads because it uses TCanvas. If thread loading is required call Synchronize() beforehand or limit the size of the returned image.
If you use LoadFromFile to load metafiles or the first overload then the default settings are used, such as EMFBackgroundColor
If NativePixelFormat = True image will be returned in ie32RGB format with alpha in the A channel


Examples

// Import vectorial image 'alfa.wmf', resizing to 500xHHH (HHH is auto-calculated)
ImageEnView1.IO.ImportMetafile( 'C:\alfa.wmf', 500, -1, true, clWhite );

// We want a maximum imported image size of 1024 pixels (in either dimension) when loading EMF or WMF files
IEGlobalSettings().MaxImageEMFSize := 1024;
ImageEnView1.IO.ImportMetafile( 'C:\input.wmf' );

// Import with a solid white background
ImageEnView1.IO.ImportMetaFile( 'C:\input.wmf', -1, -1, False, clWhite );