Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Not A Problem
-
1.9
-
None
-
Debian 9
SDK 1.8.0_151
Description
I'm having a tough time with PNGTranscoder. I am rendering an SVG document into a PNG image of different sizes. For that, I use a factor.
final float factor = 1.0f; // Load document final SAXSVGDocumentFactory DOCUMENT_FACTORY = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName()); SVGDocument document = DOCUMENT_FACTORY.createSVGDocument("ehld.svg"); // Extract original height and width final SVGSVGElement root = document.getRootElement(); final String viewBox = root.getAttributes().getNamedItem("viewBox").getNodeValue(); final Scanner scanner = new Scanner(viewBox); scanner.useLocale(Locale.UK); float x = scanner.nextFloat(); float y = scanner.nextFloat(); float width = scanner.nextFloat(); float height = scanner.nextFloat(); // Set png width and height final float w = width * factor; final float h = height * factor; final ImageTranscoder transcoder = new PNGTranscoder(); transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, w); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, h); // Export final TranscoderInput input = new TranscoderInput(document); final File file = new File("output.png"); final TranscoderOutput output = new TranscoderOutput(new FileOutputStream(file)); transcoder.transcode(input, output);
For some factors, it works nicely, but there are some of them that crash with:
Enclosed Exception:
Unable to transform src image
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:132)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
at visual.VisualTesting.test(VisualTesting.java:298)
at visual.VisualTesting.main(VisualTesting.java:64)
From 0.1 to 2.0 (step 0.1) it does NOT work with 0.7, 1.3, 1.4, 1.5, 1.7.
When I remove the filter in the SVG document (style="filter:url(#selection-filter)", line 1188) problems dissapear.
Not sure if a bug or a misusage. Thanks