[Date Prev][Date Next][Index][Thread]
[SGT Mail Archive]
[SGT Main Page]
Re: Printing to a PNG image
- To: Nicolas Michael <software@nmichael.de>
- Subject: Re: Printing to a PNG image
- From: Jon Blower <jdb@mail.nerc-essc.ac.uk>
- Date: Mon, 22 Oct 2007 15:15:35 +0100
- Cc: sgt@noaa.gov
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=FWVNzwVFry4Q/4bgtMGJ5xu7vZam9CLOxEEXvugRmKA=; b=F+BJIMsoUkvToT/n/YVrOgFN/0DQeHqVy95a5nquxWQt8z/QHdsR/5cdpI5PgMFZMeg/U2uG+/v0MBzwVPsq0ypXoP66sSWlHE3fNaRSpvcuH1GcheRitDuKWYmM9XEuoiCOiqXqyGBBghbcBvdmvWLoAMoedlcUQCC2i/Wut3o=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=EICM64h3RJIJajqPxe25Hc43z/mV9g6CaA2zPZGzecog+79tsXLsfvR/3JTErljpfefhst3pn3fPCq+HcZO5DCZ1xzFFUTsSi6x+ZQMi15xOGTokQFzU3Rd7gwexwBsEB95YRLjyVoQaBKxpOkSmPQHVd7dURTMpodelE2qm968=
- In-reply-to: <200710102235.50326.software@nmichael.de>
- References: <200710102235.50326.software@nmichael.de>
- Reply-to: Jon Blower <jdb@mail.nerc-essc.ac.uk>
- Sender: owner-sgt@noaa.gov
*************************************************
Message from the sgt mail list.
*************************************************
Dear Nicolas,
I have wrestled with a similar problem, although it was a while ago
now and I don't fully remember how I solved it! However, maybe the
following will help:
1) Conversation on this mailing list:
http://www.epic.noaa.gov/java/sgt/mail/msg00383.html.
2) Random extract from my notes:
---- Begin notes ----
This works but draws the plot with borders etc and uses addNotify(),
which isn't really supposed to be called directly.
See http://mail.epic.noaa.gov/sgt/msg00148.html
BufferedImage im = new BufferedImage(500, 500,
BufferedImage.TYPE_4BYTE_ABGR);
JGridDemo demo = new JGridDemo();
JPlotLayout graph = demo.makeGraph();
graph.getComponent().addNotify();
graph.getComponent().validate();
graph.draw(im.createGraphics());
ImageIO.write(im, "png", new File("C:\\jplot.png"));
---- End notes ----
I'm now working on other things so I probably won't be of much help in
deciphering this if it's not clear to you I'm afraid. However I'll
help if I can.
Let me know if this works for you!
Cheers, Jon
On 10/10/07, Nicolas Michael <software@nmichael.de> wrote:
> *************************************************
> Message from the sgt mail list.
> *************************************************
>
> Hello,
>
> I'm using SGT for displaying graphs, which works fine in my GUI application.
> Also printing the graph that is displayed on the screen into a PNG image works
> fine.
>
> However, I'm trying to also create graphs in an command-line mode (not
> displaying them within a JFrame) and directly writing them to a PNG image.
> This
> always results in an empty (all white) image.
>
> This is basically the code I use:
>
> public class GraphPanel extends gov.noaa.pmel.sgt.JPane {
> ....
>
> public void updateGraphPanel() {
> ... layers and graphs created inside this method ...
> }
>
> public void saveImageToFile(String fname) {
> int width = this.getWidth();
> int height = this.getHeight();
>
> BufferedImage img = new
> BufferedImage(width,height,BufferedImage.TYPE_4BYTE_ABGR);
> Graphics2D g = (Graphics2D)img.getGraphics();
> try {
> g.setBackground(Color.WHITE);
> this.paintComponent(g);
> File file = new File(fname);
> javax.imageio.ImageIO.write(img, "PNG", file);
> } catch (Exception ee) {
> ee.printStackTrace();
> } finally {
> g.dispose();
> }
> }
> }
>
> GraphPanel graphPanel = new GraphPanel(project,1024,768); // create new
> GraphPanel with size 1024x768
> graphPanel.updateGraphPanel(); // create all layers and graphs
> graphPanel.saveImageToFile("test.png");
>
> I only get a 1024x768 pixel white png image. I already played around with
> setBatch(), doLayout(), draw() etc. but couldn't find the right solution.
>
> Any help appreciated!
>
> Nick.
>
>
> *************************************************
> To remove yourself from this mailing list,
> send mail to <epic-majordomo@noaa.gov> with
> "unsubscribe sgt" in the message body.
>
--
--------------------------------------------------------------
Dr Jon Blower Tel: +44 118 378 5213 (direct line)
Technical Director Tel: +44 118 378 8741 (ESSC)
Reading e-Science Centre Fax: +44 118 378 6413
ESSC Email: jdb@mail.nerc-essc.ac.uk
University of Reading
3 Earley Gate
Reading RG6 6AL, UK
--------------------------------------------------------------
*************************************************
To remove yourself from this mailing list,
send mail to <epic-majordomo@noaa.gov> with
"unsubscribe sgt" in the message body.
Privacy Notice,
External Links Disclaimer.