diff --git a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java index 46b629f97e8..083b4933e72 100644 --- a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java +++ b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java @@ -16,7 +16,6 @@ import java.awt.*; import java.awt.image.*; import java.io.*; -import java.nio.charset.StandardCharsets; import java.util.*; import org.eclipse.swt.graphics.SVGRasterizer; import org.eclipse.swt.graphics.ImageData; @@ -58,14 +57,12 @@ public static void intializeJSVGRasterizer() { ); @Override - public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOException { + public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException { if(svgLoader == null) { svgLoader = new SVGLoader(); } SVGDocument svgDocument = null; - try (InputStream stream = new ByteArrayInputStream(bytes)) { - svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault()); - } + svgDocument = svgLoader.load(stream, null, LoaderContext.createDefault()); if (svgDocument != null) { FloatSize size = svgDocument.size(); double originalWidth = size.getWidth(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java index 2c8ef36faa5..6da8c5b23ff 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java @@ -25,14 +25,14 @@ public interface SVGRasterizer { * Rasterizes an SVG image from the provided byte array, using the specified * zoom factor. * - * @param bytes the SVG image as a byte array. + * @param stream the SVG image as an {@link InputStream}. * @param scalingFactor the scaling ratio e.g. 2.0 for doubled size. * @return the {@link ImageData} for the rasterized image, or * {@code null} if the input is not a valid SVG file or cannot be * processed. * @throws IOException if an error occurs while reading the SVG data. */ - public ImageData rasterizeSVG(byte[] bytes, float scalingFactor) throws IOException; + public ImageData rasterizeSVG(InputStream stream, float scalingFactor) throws IOException; /** * Determines whether the given {@link InputStream} contains a SVG file. diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java index 6928deedbca..afd2da911d8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/ImageLoader.java @@ -189,10 +189,12 @@ public ImageData[] load(InputStream stream, int zoom) { try (InputStream imageStream = new ByteArrayInputStream(bytes)) { if (rasterizer.isSVGFile(imageStream)) { float scalingFactor = zoom / 100.0f; - ImageData rasterizedData = rasterizer.rasterizeSVG(bytes, scalingFactor); - if (rasterizedData != null) { - data = new ImageData[]{rasterizedData}; - return data; + try (InputStream svgFileStream = new ByteArrayInputStream(bytes)) { + ImageData rasterizedData = rasterizer.rasterizeSVG(svgFileStream, scalingFactor); + if (rasterizedData != null) { + data = new ImageData[]{rasterizedData}; + return data; + } } } } catch (IOException e) {