What is the correct alternative for “com.intellij.ui.svg.loadSvg()”?
Code:
val url = URI.create(iconUrl).toURL()
val svgContent = url.readText()
val bufferedImage: BufferedImage = loadSvg(
data = svgContent.byteInputStream().readBytes(),
scale = scale.toFloat(),
)
val loadedIcon = ImageIcon(bufferedImage)
Requirement:
Using an SVG URL, I need to get a scaled version of it to render it in the UI.
Hi @yuriy.artamonov ,
Are you referring to this one? ‘com.intellij.ui.svg.JSvgDocument.Companion’ is declared in unstable ‘com.intellij.ui.svg.JSvgDocument’ marked with @ApiStatus.Internal.
JetBrains is using a forked version of JSVG. Unfortunately, some useful APIs are private in this version (I don’t know why).
Consider using the original JSVG: GitHub - weisJ/jsvg: Java SVG renderer. Its APIs are more open.
If you want to stick to the JetBrains’ fork, you can scale your imagesby using ImageUtil.scaleImage. This is what I’m doing in a plugin. I found no workaround to load an image from bytes, so I load images from files directly (file://) or from resources.