Class FlatSVGUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateWindowIconImages
(String svgName) Creates from the given SVG a list of icon images with different sizes that can be used for windows headers.createWindowIconImages
(URL svgUrl) Creates from the given SVG a list of icon images with different sizes that can be used for windows headers.private static URL
getResource
(String svgName) private static BufferedImage
svg2image
(com.github.weisj.jsvg.SVGDocument document, int width, int height) Creates a buffered image and renders the given SVGDocument into it.static BufferedImage
Creates a buffered image and renders the given SVG into it.static BufferedImage
Creates a buffered image and renders the given SVG into it.static BufferedImage
Creates a buffered image and renders the given SVG into it.static BufferedImage
Creates a buffered image and renders the given SVG into it.
-
Constructor Details
-
FlatSVGUtils
public FlatSVGUtils()
-
-
Method Details
-
createWindowIconImages
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:
RuntimeException
- if failed to load or render SVG file- See Also:
-
createWindowIconImages
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:
RuntimeException
- if failed to load or render SVG file- Since:
- 2
- See Also:
-
svg2image
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:
RuntimeException
- if failed to load or render SVG file
-
svg2image
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:
RuntimeException
- if failed to load or render SVG file- Since:
- 2
-
svg2image
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:
RuntimeException
- if failed to load or render SVG file
-
svg2image
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:
RuntimeException
- if failed to load or render SVG file- Since:
- 2
-
svg2image
private static 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:
RuntimeException
- if failed to render SVG file
-
getResource
-