SvgReader Constructor (String, SvgReaderSettings)

Initializes a new instance of the SvgReader class for the specified file, using the specified settings.

Namespace: Aurigma.GraphicsMill.Codecs
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public SvgReader(
	string fileName,
	SvgReaderSettings settings
)

Parameters

fileName

Type: System.String

The path to the SVG file.
settings

Type: Aurigma.GraphicsMill.Codecs.SvgReaderSettings

The settings used to read the file.

Remarks

The reader copies the settings. Changes to settings after this call do not affect the reader.

The images that the SVG file references are loaded in this constructor. If ResolveImage throws an exception, this constructor throws it.

Examples

C#
const string assetsPrefix = "assets/";
const string assetsFolder = @"Images";

var settings = new SvgReaderSettings();

// The SVG file refers to images in the "assets" folder, which is stored somewhere else.
settings.ResolveImage = args =>
{
    if (args.Href.StartsWith(assetsPrefix, StringComparison.OrdinalIgnoreCase))
    {
        var fileName = System.IO.Path.Combine(assetsFolder, args.Href.Substring(assetsPrefix.Length));

        // The reader takes the image when the property is set, so you can dispose the bitmap right away.
        using (var bitmap = new Bitmap(fileName))
        {
            args.Image = bitmap;
        }
    }

    // If you set neither Image nor GraphicsContainer, the image is loaded from the folder of the SVG file.
};

using (var reader = new SvgReader(@"Images\SvgWithImage.svg", settings))
using (var writer = ImageWriter.Create(@"Images\Output\SvgWithImage.png"))
{
    Pipeline.Run(reader + writer);
}

The SVG file rendered with the image that the callback loads.

The SVG file rendered with the image that the callback loads.

Exceptions

Exception Condition
System.ArgumentNullException The file name or the settings are null.

See Also

Reference