xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mariusz Chmielewski <mchm...@isi.wat.waw.pl>
Subject Merging two SVG and sending them as an ImageIcon
Date Mon, 16 Jan 2006 13:33:08 GMT
I am using JDOM to parse the SVG files becouse when i use Batic i always 
get an exception ... what am i doing wrong ?? th eproblem is that i 
would like to cut whole content of svg tree from one file and insert it 
in another:
using JDOM it goes like this:

private static ArrayList<Element> parseSVGElementSource(URL path)
            throws IOException, JDOMException {
        // wklejana jes cala sekcja <g>
        ArrayList<Element> result = new ArrayList<Element>();

        SAXBuilder builder = new SAXBuilder();
        Document doc = (Document) builder.build(path);
        Element root = doc.getRootElement();
        // List groups = root.getChildren("g");
        List groups = root.getChildren();
        for (int i = 0; i < groups.size(); i++) {
            Object temp = groups.get(i);
            // wyciagam wszystkie elementy bezposrednio podpiete pod 
            // SVG
            if (temp instanceof Element) {
                Element elem = (Element) temp;
                Content cont = elem.detach();
                // Element nElem = new Element(elem.getName());
                // nElem.setContent(elem.getChildren());

                result.add((Element) cont);

        return result;

    public static Document mergeSVGDocs(URL destinationPath, URL sourcePath)
            throws IOException, JDOMException {
        // wklejana jes cala sekcja <g>
        ArrayList<Element> result = null;

        SAXBuilder builder = new SAXBuilder();
        Document doc = (Document) builder.build(destinationPath);
        Element root = doc.getRootElement();


        return doc;

then i want to produce a ImageIcon from the merged Document and i always 
get an error:

my method looks like this:

        ArrayList<Element> result = null;

        SAXBuilder builder = new SAXBuilder();
        Document doc = (Document) builder.build(baseSign);
        Element root = doc.getRootElement();


        // canva.setDocument(new DOMOutputter().output(doc));
        // JSVGCanvas canva = new JSVGCanvas();
        // canva.setDocument(new DOMOutputter().output(doc));

        //TranscoderOutput to = new TranscoderOutput(new DOMOutputter()
        //        .output(doc));
        File nameDest = new File("c.jpeg");
        //FileOutputStream fos = new FileOutputStream(nameDest);
        ByteArrayOutputStream boa = new ByteArrayOutputStream();
        TranscoderOutput to = new TranscoderOutput(boa);
        String path = new File ("a.svg").toURL().toString();
        TranscoderInput ti = new TranscoderInput(path);
        //TranscoderInput ti = new TranscoderInput(new 
        JPEGTranscoder pngProducer = new JPEGTranscoder();
        pngProducer.transcode(ti, to);
                new Float(.9));
        BufferedImage img = pngProducer.createImage(100, 100);
        //BufferedImage img = new 
        pngProducer.writeImage(img, to);
        return new ImageIcon(img);

its messy but i tried different thins to produce valid ImageIcon ... no 
results Yet i always get black image



To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message