Dear All,
Thank you for your previous reply.
What I was trying to do is to generate a svg containing all the gene
locations on the genome in one single file, then cut the entire svg into
small tiles.
I tried on mapWaadt.svg came with Batik, it worked fine.
But I tried my own svg file, generated by perl and renderable by Adobe svg
plugin, Batik throws exception.
I have attached source codes.
I don't know it's my svg's problem or Batik, as it throwed
thread "main" java.lang.OutOfMemoryError: Java heap space error.
Thank you very much!
Gang Su
Bioinformatics Student, University of Michigan
Java code:
package svgBatik;
import java.io.*;
import java.awt.*;
import java.io.IOException;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.w3c.dom.Document;
public class ImageTest {
public static void main(String[] args)
{
try{
String parser =
XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new
SAXSVGDocumentFactory(parser);
//String uri =
"file:/d:/SVG/Batik/batik-1.7/samples/mapWaadt.svg";
String uri = "file:/d:/perlSVG.svg";
Document doc = f.createDocument(uri);
//complex grammar...
//NO error was thrown. The parsing was successuful.
System.out.println("Parsing Completed");
//define input
TranscoderInput input = new TranscoderInput(doc);
//initialize as a document
//define output
OutputStream ostream = new
FileOutputStream("d:/outsvg.png");
TranscoderOutput output = new TranscoderOutput(ostream);
//define transcoder
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(PNGTranscoder.KEY_AOI, new
Rectangle(500,0,1000,50));
t.transcode(input, output);
}
catch (Exception ex)//easy way is to catch the general
exception, well..
{
System.out.println(ex.toString());
}
}
}
Part of the svg:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/css" href="svgStyle.css" ?>
<svg height="50" id="document_element" width="250000"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<rect class="rect" height="20" width="3" x="1" y="10" />
<rect class="rect" height="20" width="10" x="4" y="10" />
<rect class="rect" height="20" width="15" x="4" y="10" />
<rect class="rect" height="20" width="3" x="4" y="10" />
<rect class="rect" height="20" width="5" x="4" y="10" />
<rect class="rect" height="20" width="15" x="4" y="10" />
<rect class="rect" height="20" width="2" x="5" y="10" />
<rect class="rect" height="20" width="13" x="6" y="10" />
<rect class="rect" height="20" width="3" x="6" y="10" />
<rect class="rect" height="20" width="12" x="7" y="10" />
<rect class="rect" height="20" width="1" x="24" y="10" />
<rect class="rect" height="20" width="1" x="58" y="10" />
<rect class="rect" height="20" width="0" x="127" y="10" />
<rect class="rect" height="20" width="0" x="127" y="10" />
<rect class="rect" height="20" width="0" x="128" y="10" />
<rect class="rect" height="20" width="0" x="129" y="10" />
<rect class="rect" height="20" width="0" x="310" y="10" />
<rect class="rect" height="20" width="0" x="311" y="10" />
<rect class="rect" height="20" width="0" x="314" y="10" />
<rect class="rect" height="20" width="0" x="314" y="10" />
<rect class="rect" height="20" width="0" x="314" y="10" />
<rect class="rect" height="20" width="1" x="317" y="10" />
<rect class="rect" height="20" width="1" x="357" y="10" />
<rect class="rect" height="20" width="1" x="410" y="10" />
<rect class="rect" height="20" width="2" x="552" y="10" />
<rect class="rect" height="20" width="1" x="556" y="10" />
<rect class="rect" height="20" width="0" x="558" y="10" />
<rect class="rect" height="20" width="0" x="558" y="10" />
<rect class="rect" height="20" width="1" x="559" y="10" />
<rect class="rect" height="20" width="1" x="610" y="10" />
<rect class="rect" height="20" width="0" x="653" y="10" />
<rect class="rect" height="20" width="0" x="653" y="10" />
<rect class="rect" height="20" width="0" x="654" y="10" />
<rect class="rect" height="20" width="0" x="654" y="10" />
<rect class="rect" height="20" width="0" x="658" y="10" />
<rect class="rect" height="20" width="0" x="658" y="10" />
<rect class="rect" height="20" width="0" x="658" y="10" />
<rect class="rect" height="20" width="0" x="661" y="10" />
<rect class="rect" height="20" width="0" x="665" y="10" />
</svg>
Thank you very much!