ImageEn, unit imageenio

TImageEnIO.ImportFromStreamSVG

TImageEnIO.ImportFromStreamSVG


Declaration

function ImportFromStreamSVG(Stream: TStream; Width: Integer = -1; Height: Integer = -1; MaintainAR: Boolean = False): Boolean;


Description

Loads a rasterized image from a stream containing a SVG file.

With Skia and ImageMagick you can specify the import size (not with native SVF support).
Set Width and Height to the desired image size (the rectangle where the SVG image will be drawn). 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. ImportFromFileSVG( 'axi.svg', -1, 500 ); or set both values and enable MaintainAR.

The result will be false if an error is encountered, e.g. the file in the stream is not SVG format (Aborting will be true).


Note:
To import SVG files as vector layers, use LayersImport
Improved SVG rasterized rendering is available with Delphi 12 or newer using Skia. You must add Vcl.Skia to the uses clause (of any of your project units) and enable Skia for your project
For improved SVG load support, use ImageMagick
This method loads the image as a bitmap (rasterized). It will not be in vector format. To load as SVG as vector layers, use LayersImport
Does not reset the position of the stream, so you may need to first call Stream.Position := 0;
If NativePixelFormat = True, the image will be returned in ie32RGB format with alpha in the A channel


Example

uses
  Vcl.Skia;

// Import an SVG file
if ImageEnView1.IO.ImportFromStreamSVG(fs) = False then
  ShowMessage('Not an SVG file!');


See Also

ImportFromFileSVG
AsSVG
SVG Implementation Status