Hi,

i'm new to Batik. I've searched the archive to find an answer to my problem,
but I didn't find anything.

We're developing a tool to visualise networks. We'd like to be able to
export them to different graphic formats.

Exporting to svg is no problem.
For export to JPG, TIF and PNG, i first create a temporary svg file and then
transcode that file to one of those formats.
What seems to be the problem:
the svg file doesn't have width or height attributes. Displaying a 1000*1000
svg file is no problem, but when I transcode it, it clips the image to the
upper left 400*400 pixels.

Is there a way to solve this?

Thanks in advance,
Brecht

Code:
 /**
  * Export a visualisation to the SVG format
  *
  * @param vis the visualisation to be exported
  * @param fileName the filename under which it should be saved
  * @return the filename
  */
 public static File exportToSVG(Visualisation vis, String fileName){
  logger.debug("");
  File file = new File(fileName);
  DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
  Document document = domImpl.createDocument(null, "svg", null);
  SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);

  ctx.setComment("Generated by Trs-visualisation");
  SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);

    // render visualisation height 1000 and width 1000
  vis.render(svgGenerator, 1000, 1000, null);

  boolean useCSS = false;

  try {
   Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
   svgGenerator.stream(out, useCSS);
  } catch (IOException e) {
   logger.error(e);
  }

  return file;
 }

 /**
  * Export a visualisation to the JPG format
  *
  * @param vis the visualisation to be exported
  * @param fileName the filename under which it should be saved
  * @return the filename
  */
 public static File exportToJPG(Visualisation vis, String filename) {
  logger.debug("");
  File file = new File(filename);
  JPEGTranscoder t = new JPEGTranscoder();
  t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
  t.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(1000));
  //t.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, new Float(1000));
  transcode(vis, file, t);
  return file;
 }

 /**
  * Create an image from a visualisation
  *
  * @param vis the visualisation
  * @param file the filename
  * @param t the transcoder used to create the image
  */
 private static void transcode(Visualisation vis, File file, ImageTranscoder
t){
  logger.debug("");
  String svgURI = null;
  try {
   svgURI = exportToSVG(vis, "temp.svg").toURL().toString();
  } catch (MalformedURLException e) {
   logger.error(e);
  }
  TranscoderInput input = new TranscoderInput(svgURI);
  OutputStream ostream = null;
  try {
   ostream = new FileOutputStream(file);
  } catch (FileNotFoundException e3) {
   // TODO Auto-generated catch block
   e3.printStackTrace();
  }
  TranscoderOutput output = new TranscoderOutput(ostream);
  try {
   t.transcode(input, output);
  } catch (TranscoderException e1) {
   logger.error(e1);
  }
  try {
   ostream.flush();
   ostream.close();
  } catch (IOException e2) {
   logger.error(e2);
  }
  new File("temp.svg").delete();
 }
-- 
Light, sound, drums, guitar, let there be rock!



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to