Class SVGUtil
java.lang.Object
com.dlsc.gemsfx.util.SVGUtil
A utility class that provides methods for parsing SVG files and converting them to JavaFX Image objects.
This class provides methods for loading SVG documents from various sources, such as files, URLs, and input streams, and then rendering them to JavaFX Image objects.
Note for SVGUtil: Currently, due to the limitation that weisj can only render BufferedImage from SVG, SvgImageView does not support usage in native packaging scenarios.-
Method Summary
Modifier and TypeMethodDescriptionstatic javafx.scene.image.ImageparseSVGFromFile(File svgFile) Parses an SVG file from a given File object.static javafx.scene.image.ImageparseSVGFromFile(File svgFile, double prefWidth, double prefHeight) Parses an SVG file from a given File object with the specified width and height.static javafx.scene.image.ImageparseSVGFromFile(String svgFilePath) Parses an SVG file from a given file path.static javafx.scene.image.ImageparseSVGFromUrl(String urlString) Parses an SVG file from a given URL string.static javafx.scene.image.ImageparseSVGFromUrl(URL url) Parses an SVG file from a given URL object.static javafx.scene.image.ImageparseSVGFromUrl(URL url, double prefWidth, double prefHeight) Parses an SVG file from a given URL object with the specified width and height.static javafx.scene.image.ImagetoImage(File svgFile, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) static javafx.scene.image.ImagetoImage(InputStream is, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts an InputStream representing an SVG file to an Image object with the specified dimensions and scale factors.static javafx.scene.image.ImagetoImage(String urlStr, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts a URL string representing an SVG file to an Image object with the specified dimensions and scale factors.static javafx.scene.image.ImagetoImage(URL url, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts a URL representing an SVG file to an Image object with the specified dimensions and scale factors.
-
Method Details
-
parseSVGFromFile
Parses an SVG file from a given file path.- Parameters:
svgFilePath- the file path of the SVG file.- Returns:
- an Image object representing the parsed SVG file.
-
parseSVGFromFile
Parses an SVG file from a given File object.- Parameters:
svgFile- the File object representing the SVG file.- Returns:
- an Image object representing the parsed SVG file.
-
parseSVGFromFile
public static javafx.scene.image.Image parseSVGFromFile(File svgFile, double prefWidth, double prefHeight) Parses an SVG file from a given File object with the specified width and height.- Parameters:
svgFile- the File object representing the SVG file.prefWidth- the preferred width of the Image.prefHeight- the preferred height of the Image.- Returns:
- an Image object representing the parsed SVG file.
-
parseSVGFromUrl
Parses an SVG file from a given URL string.- Parameters:
urlString- the URL string of the SVG file.- Returns:
- an Image object representing the parsed SVG file.
-
parseSVGFromUrl
Parses an SVG file from a given URL object.- Parameters:
url- the URL object of the SVG file.- Returns:
- an Image object representing the parsed SVG file.
-
parseSVGFromUrl
public static javafx.scene.image.Image parseSVGFromUrl(URL url, double prefWidth, double prefHeight) Parses an SVG file from a given URL object with the specified width and height.- Parameters:
url- the URL object of the SVG file.prefWidth- the preferred width of the Image.prefHeight- the preferred height of the Image.- Returns:
- an Image object representing the parsed SVG file.
-
toImage
public static javafx.scene.image.Image toImage(InputStream is, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts an InputStream representing an SVG file to an Image object with the specified dimensions and scale factors.- Parameters:
is- the InputStream of the SVG file.requestedWidth- the preferred width of the Image.requestedHeight- the preferred height of the Image.outputScaleX- the horizontal scale factor.outputScaleY- the vertical scale factor.- Returns:
- an Image object representing the SVG file.
-
toImage
public static javafx.scene.image.Image toImage(URL url, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts a URL representing an SVG file to an Image object with the specified dimensions and scale factors.- Parameters:
url- the URL of the SVG file.requestedWidth- the preferred width of the Image.requestedHeight- the preferred height of the Image.outputScaleX- the horizontal scale factor.outputScaleY- the vertical scale factor.- Returns:
- an Image object representing the SVG file.
-
toImage
public static javafx.scene.image.Image toImage(String urlStr, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY) Converts a URL string representing an SVG file to an Image object with the specified dimensions and scale factors.- Parameters:
urlStr- the URL string of the SVG file.requestedWidth- the preferred width of the Image.requestedHeight- the preferred height of the Image.outputScaleX- the horizontal scale factor.outputScaleY- the vertical scale factor.- Returns:
- an Image object representing the SVG file.
-
toImage
public static javafx.scene.image.Image toImage(File svgFile, double requestedWidth, double requestedHeight, double outputScaleX, double outputScaleY)
-