[Biojava-l] logo painter

Bert Coessens Bert.Coessens@esat.kuleuven.ac.be
Fri, 11 Jan 2002 14:21:26 +0100


Dear all,

Does anybody know how to write a graphics object to a jpeg file? I
already tried almost everything but still with no result. The code
beneath is what I think should work, but if I run it, I only get a black
image of 300 by 300. Can anybody tell me what I'm doing wrong?

* variable dist is some distance
* sLogo is not a null object, I can visualise it inside a JFrame object

code:
    {
        DistributionLogo sLogo = new DistributionLogo();
        TextLogoPainter logoPainter = new TextLogoPainter();
        sLogo.setLogoPainter(logoPainter);
        sLogo.setStyle(new DNAStyle());
        sLogo.setDistribution(dist);

        BufferedImage bufIm = new BufferedImage(300, 300,
BufferedImage.TYPE_INT_RGB);
        Graphics g = bufIm.createGraphics();
        logoPainter.paintLogo(g, sLogo);

        File outfile = new File("motif.jpeg");
        FileOutputStream outstream = new FileOutputStream(outfile);
        com.sun.image.codec.jpeg.JPEGImageEncoder encoder =

com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(outstream);
        encoder.encode(img);
    }

Thanks in advance!!
Bert