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 
hierarchie
            // SVG
            if (temp instanceof Element) {
                Element elem = (Element) temp;
                Content cont = elem.detach();
                System.out.println(elem.getName());
                // 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();

        root.addContent(parseSVGElementSource(sourcePath));

        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();

        root.addContent(parseSVGElementSource(elementSign));

        // 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 
DOMOutputter().output(doc));
       
       
       
        JPEGTranscoder pngProducer = new JPEGTranscoder();
        pngProducer.transcode(ti, to);
        pngProducer.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
                new Float(.9));
        pngProducer.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR,
                Color.white);
       
        BufferedImage img = pngProducer.createImage(100, 100);
        //BufferedImage img = new 
BufferedImage(100,100,BufferedImage.TYPE_BYTE_INDEXED);
       
        pngProducer.writeImage(img, to);
        img.flush();
       
        //to.getOutputStream().flush();
       
        return new ImageIcon(img);
}


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

HELP

Mchmiel


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


Mime
View raw message