Class FlatSVGUtils
- java.lang.Object
-
- com.formdev.flatlaf.extras.FlatSVGUtils
-
public class FlatSVGUtils extends java.lang.Object
Utility methods for SVG.
-
-
Constructor Summary
Constructors Constructor Description FlatSVGUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.awt.Image>
createWindowIconImages(java.lang.String svgName)
Creates from the given SVG a list of icon images with different sizes that can be used for windows headers.static java.util.List<java.awt.Image>
createWindowIconImages(java.net.URL svgUrl)
Creates from the given SVG a list of icon images with different sizes that can be used for windows headers.private static java.net.URL
getResource(java.lang.String svgName)
private static java.awt.image.BufferedImage
svg2image(com.github.weisj.jsvg.SVGDocument document, int width, int height)
Creates a buffered image and renders the given SVGDocument into it.static java.awt.image.BufferedImage
svg2image(java.lang.String svgName, float scaleFactor)
Creates a buffered image and renders the given SVG into it.static java.awt.image.BufferedImage
svg2image(java.lang.String svgName, int width, int height)
Creates a buffered image and renders the given SVG into it.static java.awt.image.BufferedImage
svg2image(java.net.URL svgUrl, float scaleFactor)
Creates a buffered image and renders the given SVG into it.static java.awt.image.BufferedImage
svg2image(java.net.URL svgUrl, int width, int height)
Creates a buffered image and renders the given SVG into it.
-
-
-
Method Detail
-
createWindowIconImages
public static java.util.List<java.awt.Image> createWindowIconImages(java.lang.String svgName)
Creates from the given SVG a list of icon images with different sizes that can be used for windows headers. The SVG should have a size of 16x16, otherwise it is scaled.If running on Windows in Java 9 or later and multi-resolution image support is available, then a single multi-resolution image is returned that creates images on demand for requested sizes from SVG. This has the advantage that only images for used sizes are created. Also, if unusual sizes are requested (e.g. 18x18), then they are created from SVG.
If using Java modules, the package containing the SVG must be opened in
module-info.java
. Otherwise, usecreateWindowIconImages(URL)
.- Parameters:
svgName
- the name of the SVG resource (a '/'-separated path)- Returns:
- list of icon images with different sizes (16x16, 20x20, 24x24, 28x28, 32x32, 48x48 and 64x64)
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file- See Also:
Window.setIconImages(List)
-
createWindowIconImages
public static java.util.List<java.awt.Image> createWindowIconImages(java.net.URL svgUrl)
Creates from the given SVG a list of icon images with different sizes that can be used for windows headers. The SVG should have a size of 16x16, otherwise it is scaled.If running on Windows in Java 9 or later and multi-resolution image support is available, then a single multi-resolution image is returned that creates images on demand for requested sizes from SVG. This has the advantage that only images for used sizes are created. Also, if unusual sizes are requested (e.g. 18x18), then they are created from SVG.
This method is useful if using Java modules and the package containing the SVG is not opened in
module-info.java
. E.g.createWindowIconImages( getClass().getResource( "/com/myapp/myicon.svg" ) )
.- Parameters:
svgUrl
- the URL of the SVG resource- Returns:
- list of icon images with different sizes (16x16, 20x20, 24x24, 28x28, 32x32, 48x48 and 64x64)
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file- Since:
- 2
- See Also:
Window.setIconImages(List)
-
svg2image
public static java.awt.image.BufferedImage svg2image(java.lang.String svgName, int width, int height)
Creates a buffered image and renders the given SVG into it.If using Java modules, the package containing the SVG must be opened in
module-info.java
. Otherwise, usesvg2image(URL, int, int)
.- Parameters:
svgName
- the name of the SVG resource (a '/'-separated path)width
- the width of the imageheight
- the height of the image- Returns:
- the image
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file
-
svg2image
public static java.awt.image.BufferedImage svg2image(java.net.URL svgUrl, int width, int height)
Creates a buffered image and renders the given SVG into it.This method is useful if using Java modules and the package containing the SVG is not opened in
module-info.java
. E.g.svg2image( getClass().getResource( "/com/myapp/myicon.svg" ), 24, 24 )
.- Parameters:
svgUrl
- the URL of the SVG resourcewidth
- the width of the imageheight
- the height of the image- Returns:
- the image
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file- Since:
- 2
-
svg2image
public static java.awt.image.BufferedImage svg2image(java.lang.String svgName, float scaleFactor)
Creates a buffered image and renders the given SVG into it.If using Java modules, the package containing the SVG must be opened in
module-info.java
. Otherwise, usesvg2image(URL, float)
.- Parameters:
svgName
- the name of the SVG resource (a '/'-separated path)scaleFactor
- the amount by which the SVG size is scaled- Returns:
- the image
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file
-
svg2image
public static java.awt.image.BufferedImage svg2image(java.net.URL svgUrl, float scaleFactor)
Creates a buffered image and renders the given SVG into it.This method is useful if using Java modules and the package containing the SVG is not opened in
module-info.java
. E.g.svg2image( getClass().getResource( "/com/myapp/myicon.svg" ), 1.5f )
.- Parameters:
svgUrl
- the URL of the SVG resourcescaleFactor
- the amount by which the SVG size is scaled- Returns:
- the image
- Throws:
java.lang.RuntimeException
- if failed to load or render SVG file- Since:
- 2
-
svg2image
private static java.awt.image.BufferedImage svg2image(com.github.weisj.jsvg.SVGDocument document, int width, int height)
Creates a buffered image and renders the given SVGDocument into it.- Parameters:
document
- the SVG documentwidth
- the width of the imageheight
- the height of the image- Returns:
- the image
- Throws:
java.lang.RuntimeException
- if failed to render SVG file
-
getResource
private static java.net.URL getResource(java.lang.String svgName)
-
-