width parameter as the width of the resulting imageSnapshotParameters It is possible to set the parameters to use by using the following methods:
It is possible to specify the default SVGSnapshotParameters to use when creating snapshots by using the SVGImage.setDefaultSnapshotParameters(SVGSnapshotParameters) method.
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"> <path d="M160-440v-80h640v80H160Z"/> </svg>If you use the following code:
URL url = <my SVG content> SVGImage result = SVGLoader.load(url); Image img = result.toImage();The width and height of the image will be (16 px, 2 px), which is the size of the path.
URL url = <my SVG content> SVGImage result = SVGLoader.load(url); SVGSnapshotParameters params = new SVGSnapshotParameters(); params.setViewportType(SVGSnapshotParameters.USE_BEST_VIEWPORT_SIZE); Image img = result.toImage(params);The width and height of the image will be (24 px, 24 px), which is the size of the viewport.
SVGImage img = SVGLoader.load(<my SVG file>); // the resulting image will have a width of 100 pixels Image fxImg = img.toImage(100); // the resulting image will be scaled by a 0.5 factor Image fxImg2 = img.toImageScaled(0.5d); // the resulting image will have a width of 50 pixels, but the image will be scaled at the SVG level before creating the image Image fxImg2 = img.toImage(ScaleQuality.RENDER_QUALITY, 50);
Copyright 2021-2022 Herve Girod. All Rights Reserved. Documentation and source under the BSD-3-Clause License