Ah! Mystery solved. See: http://stackoverflow.com/questions/16138850/batik-svggraphics2d-nullpointerexception-when-drawing-image, specifically the April 14th comment to the lone answer. This comment points out a bug in Batik 1.8 (https://issues.apache.org/jira/browse/BATIK-1146). Using Batik 1.7 fixed the problem.
(Let me apologize for double post. A question I had sent the day before to the tomcat-user's list had never posted to mail-archives.apache.org, and I thought my April 30th message here was swallowed as well. As it was, it posted May 1st and I missed it.) On Fri, May 6, 2016 at 12:36 PM, Thad Humphries <thad.humphr...@gmail.com> wrote: > 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) > -- "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)