Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-1207

NPE with different PNGTranscoder.KEY_WIDTH, PNGTranscoder.KEY_HEIGHT

    XMLWordPrintableJSON

    Details

      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

        Attachments

        1. ehld.svg
          87 kB
          Pascual Lorente

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              pasculorente Pascual Lorente
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: