Processing 3.0.1 - Question about PGraphics and SVG export

import processing.svg.*;
PGraphics pgDrawing;

void setup(){
  size(400,400);
  background(255);
  pgDrawing = createGraphics(width, height);
}

void draw(){
  beginRecord(SVG, "test.svg");

  drawEllipses();
  image(pgDrawing,0,0);
  endRecord();

  noLoop();
}

void drawEllipses(){
  pgDrawing.beginDraw();
  for (int i=0; i<10; i++){
    pgDrawing.ellipse(random(0,width),random(0,height), 10,10);
  }
  pgDrawing.endDraw();
}

I'm having trouble with saving SVG's when using a or combining various PGraphics buffers. There's probably something basic I'm not getting but I'll be glad to get some advice.

The code above is just a representation of what I'm trying to do in a much bigger sketch, but it reproduces the exact error. Basically I want to combine the result from a various PGraphics into an SVG-file. The problem with the code above is that it throws a NullPointerException on line 14 at image(pgDrawing,0,0) with no explanation. I can't seem to figure it out.

In addition: I ran the sketch in debug mode and this is what it says:

Exception in thread "Animation Thread" 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 org.apache.batik.ext.awt.g2d.AbstractGraphics2D.drawImage(Unknown Source) at processing.awt.PGraphicsJava2D.imageImpl(PGraphicsJava2D.java:1597) at processing.core.PGraphics.image(PGraphics.java:3768) at processing.core.PApplet.image(PApplet.java:12108) at SVGTEST.draw(SVGTEST.java:32) at processing.core.PApplet.handleDraw(PApplet.java:2399) at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1527) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

Any thoughts?

Any help is much appreciated!

Cheers!

(Edit: I removed a double entry of pgDrawing = createGraphics(width, height); on line 12. While it didn't influence the code it was a bit silly...)

Answers

  • edited February 2016

    Just checked the forum guidelines for info about bumping questions... Found nothing, so here goes: BUMP

    Noticed that I should include platform: I'm on Windows 8.1

    I still haven't found how to fix this. There's no info at all, just an undescribed NullPointerException. But when I catch it and print getMessage() it just returns null...

    I'll keep looking, but if anyone has an explanation (for all I know I'm trying something that just doesn't work) I'll take it...

    Cheers!

  • comment line 11,12,15

  • edited February 2016

    Many thanks for your answer, but then the SVG obviously isn't saved anymore and that's the whole point...

    (Edit: debug info moved to original post, was confusing)

  • ??

    we are adressing the npe first

    did you comment it out ?

  • Yeah, sure. When I comment it out, the sketch runs, the circles are shown, but the SVG is not saved... No more NPE.

  • actually I think the svg can't register an image

    moreover it would not see the ellipses inside the image at all

    why do you need PGraphics anyway?

  • That does indeed sound logical.

    In my original sketch I wanted to put various PGraphics on top of eachother in a final svg. I wanted to use various PGraphics because I wanted to be able to apply various computer vision applications on different images and only present the vector information in my applet.

    In the standard situation I can get some vectors from an image and present it, but when I want new vectorinfo to superimpose on it I have to first put an image (or a white 'background') over it to draw the vectors. Thus rendering the first drawing invisible... (If that makes sense?)

    While I'm typing this I'm thinking there may be other ways of trying this.

    I'll keep this thread informed.

    Many thanks for your time and help...

    Cheers!

  • Right, so I did something I should've done a lot sooner. I put the images in separate PGraphics objects, gathered the OC-data and drew the vectors on the default canvas where apparentle the SVG recording is going on...

    Silly me...

    Thanks for your time! Problem solved!

    Cheers!

  • Answer ✓

    Cheers!

Sign In or Register to comment.