SvgRasterizationOptions

Inheritance: java.lang.Object, com.aspose.imaging.DisposableObject, com.aspose.imaging.ImageOptionsBase, com.aspose.imaging.imageoptions.VectorRasterizationOptions

public class SvgRasterizationOptions extends VectorRasterizationOptions

The SVG rasterization options.

Constructors

ConstructorDescription
SvgRasterizationOptions()Initializes a new instance of the SvgRasterizationOptions class.

Methods

MethodDescription
getScaleX()Gets or sets the scale x.
setScaleX(float value)Gets or sets the scale x.
getScaleY()Gets or sets the scale y.
setScaleY(float value)Gets or sets the scale y.

SvgRasterizationOptions()

public SvgRasterizationOptions()

Initializes a new instance of the SvgRasterizationOptions class.

getScaleX()

public float getScaleX()

Gets or sets the scale x.

Returns: float - The scale x.

setScaleX(float value)

public void setScaleX(float value)

Gets or sets the scale x.

Parameters:

ParameterTypeDescription
valuefloatThe scale x.

Example: This example shows how to load an SVG image from a file and rasterize it to PNG using various options.

String dir = "c:\\temp\\";

// Using Aspose.Imaging.Image.Load is a unified way to load image.
com.aspose.imaging.fileformats.svg.SvgImage svgImage = (com.aspose.imaging.fileformats.svg.SvgImage) com.aspose.imaging.Image.load(dir + "test.svg");
try {
    // In order to rasterize SVG we need to specify rasterization options.
    com.aspose.imaging.imageoptions.SvgRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.SvgRasterizationOptions();

    // Set default color of a background for an image. Default value is white.
    rasterizationOptions.setBackgroundColor(com.aspose.imaging.Color.getGray());

    // Set the page size
    rasterizationOptions.setPageSize(new com.aspose.imaging.SizeF(svgImage.getWidth(), svgImage.getHeight()));

    // Antialiasing is applied to lines and curves and the edges of filled areas.
    rasterizationOptions.setSmoothingMode(com.aspose.imaging.SmoothingMode.AntiAlias);

    // Each character is drawn using its antialiased glyph bitmap without hinting.
    rasterizationOptions.setTextRenderingHint(com.aspose.imaging.TextRenderingHint.AntiAlias);

    // Reduce the image size 10 times, i.e. the output size will be 10% of the original size.
    rasterizationOptions.setScaleX(0.1f);
    rasterizationOptions.setScaleY(0.1f);

    com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
    saveOptions.setVectorRasterizationOptions(rasterizationOptions);

    // Save to a PNG file
    svgImage.save(dir + "test.output.png", saveOptions);
} finally {
    svgImage.dispose();
}

getScaleY()

public float getScaleY()

Gets or sets the scale y.

Returns: float - The scale y.

setScaleY(float value)

public void setScaleY(float value)

Gets or sets the scale y.

Parameters:

ParameterTypeDescription
valuefloatThe scale y.

Example: This example shows how to load an SVG image from a file and rasterize it to PNG using various options.

String dir = "c:\\temp\\";

// Using Aspose.Imaging.Image.Load is a unified way to load image.
com.aspose.imaging.fileformats.svg.SvgImage svgImage = (com.aspose.imaging.fileformats.svg.SvgImage) com.aspose.imaging.Image.load(dir + "test.svg");
try {
    // In order to rasterize SVG we need to specify rasterization options.
    com.aspose.imaging.imageoptions.SvgRasterizationOptions rasterizationOptions = new com.aspose.imaging.imageoptions.SvgRasterizationOptions();

    // Set default color of a background for an image. Default value is white.
    rasterizationOptions.setBackgroundColor(com.aspose.imaging.Color.getGray());

    // Set the page size
    rasterizationOptions.setPageSize(new com.aspose.imaging.SizeF(svgImage.getWidth(), svgImage.getHeight()));

    // Antialiasing is applied to lines and curves and the edges of filled areas.
    rasterizationOptions.setSmoothingMode(com.aspose.imaging.SmoothingMode.AntiAlias);

    // Each character is drawn using its antialiased glyph bitmap without hinting.
    rasterizationOptions.setTextRenderingHint(com.aspose.imaging.TextRenderingHint.AntiAlias);

    // Reduce the image size 10 times, i.e. the output size will be 10% of the original size.
    rasterizationOptions.setScaleX(0.1f);
    rasterizationOptions.setScaleY(0.1f);

    com.aspose.imaging.imageoptions.PngOptions saveOptions = new com.aspose.imaging.imageoptions.PngOptions();
    saveOptions.setVectorRasterizationOptions(rasterizationOptions);

    // Save to a PNG file
    svgImage.save(dir + "test.output.png", saveOptions);
} finally {
    svgImage.dispose();
}