xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thad Humphries <thad.humphr...@gmail.com>
Subject SVGGraphics2D drawImage() NullPointerException
Date Fri, 06 May 2016 16:36:06 GMT
I am trying to create an SVG from a BufferedImage using the example at
https://xmlgraphics.apache.org/batik/using/svg-generator.html. The image is
a TIFF read from disk using Apache Commons Imaging. I can successfully
export this image to PNG. However cannot create an SVG. The code is

  public static void main(String[] args) {
    try {
      File inFile = new File(args[0]);
      BufferedImage sourceImage = ImageReadExample.imageReadExample(inFile);
      // Imaging.writeImage(sourceImage, new File("sourceImage.png"),
ImageFormats.PNG, null);

      // Get a DOMImplementation.
      DOMImplementation domImpl =
        GenericDOMImplementation.getDOMImplementation();

      // Create an instance of org.w3c.dom.Document.
      String svgNS = "http://www.w3.org/2000/svg";
      Document document = domImpl.createDocument(svgNS, "svg", null);

      // Create an instance of the SVG Generator.
      SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

      // Ask the test to render into the SVG Graphics2D implementation.
      svgGenerator.drawImage(sourceImage, 0, 0, null);
      ...

When I end with `Imaging.writeImage(sourceImage, new
File("sourceImage.png"), ImageFormats.PNG, null);` a PNG is created.
However at `svgGenerator.drawImage(sourceImage, 0, 0, null);` I get this
stack trace:

java.lang.NullPointerException
at org.apache.batik.svggen.ImageHandlerBase64Encoder.encodeImage(Unknown
Source)
at org.apache.batik.svggen.ImageHandlerBase64Encoder.handleHREF(Unknown
Source)
at org.apache.batik.svggen.ImageHandlerBase64Encoder.handleHREF(Unknown
Source)
at org.apache.batik.svggen.DefaultImageHandler.handleImage(Unknown Source)
at org.apache.batik.svggen.SimpleImageHandler.handleImage(Unknown Source)
at org.apache.batik.svggen.SVGGraphics2D.drawImage(Unknown Source)
at com.corp.util.image.ImageReadExample.main(ImageReadExample.java:49)

I am using Batik 1.8 with Java 1.8.0_91 on MacOS 10.10.5.

-- 
"Hell hath no limits, nor is circumscrib'd In one self-place; but where we
are is hell, And where hell is, there must we ever be" --Christopher
Marlowe, *Doctor Faustus* (v. 121-24)

Mime
View raw message