How to save an image to file without rendering to screen?

Does anyone know of a way I can save a buffered image to a file (as a jpg) without having to render it to a screen first? I can create the file fine if I place the image on a JPanel first. However when I try to save the image directly to a file, the program hangs when I try to render the image to a Graphics object. Is there some sort of initialisation carried out on the image when it is displayed on screen which I need to carry out to save the image offscreen?
Just as a background, what I am trying to achieve is to create a chart (using Monarch Charts library) based on a supplied set of data, and then to save this chart as a jpg. It works fine if I first display the chart in a JPanel but not when I try to save it offscreen.
Can anyone help me out here?
Thanks,
Ciaran

Here's the code I use in JFreeChart to create a buffered image - the third line draws the chart using the Graphics2D obtained from the BufferedImage:
    public BufferedImage createBufferedImage(int width, int height) {
        BufferedImage image = new BufferedImage(width , height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        this.draw(g2, new Rectangle2D.Double(0, 0, width, height), null);
        g2.dispose();
        return image;
    }Writing to a JPEG can be done like this (method taken from the ChartUtilities class in JFreeChart):
    public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height)
        throws IOException {
        BufferedImage image = chart.createBufferedImage(width, height);
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
        param.setQuality(1.0f, true);
        encoder.encode(image, param);
    }If you want to try some running code, download JFreeChart from:
http://www.object-refinery.com/jfreechart/index.html
...then run this application:
package com.jrefinery.chart.demo;
import java.io.File;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.ChartUtilities;
import com.jrefinery.chart.demo.DemoDatasetFactory;
import com.jrefinery.data.XYDataset;
public class ChartToFile {
    public static void main(String[] args) {
        XYDataset data = DemoDatasetFactory.createTimeSeriesCollection2();
        JFreeChart chart = ChartFactory.createTimeSeriesChart("Sample Chart", "Time", "Rate", data, true);
        File file = new File("MyChart.jpg");
        try {
            ChartUtilities.saveChartAsJPEG(file, chart, 400, 300);
        catch (java.io.IOException e) {
            System.out.println(e.getMessage());
}Regards,
Dave Gilbert
www.object-refinery.com

Similar Messages

  • How can I play an audio file without the whole screen going black?

    When I play the mp3 file on IE it opens in a small screen so I can still see the web page.
    On Firefox the whole screen is taken up with the sound file being played.
    Can this be changed?

    Is that file played in a tab in the current window or in a separate pop-up window?
    Are you allowing pop-up to modify the window size (dom.disable_window_move_resize = false)?
    *http://kb.mozillazine.org/JavaScript#Advanced_JavaScript_settings
    You can try set the Boolean pref <b>media.windows-media-foundation.enabled</b> to <i>false</i> on the <b>about:config</b> page to disable the built-in HTML5 media player.
    *http://kb.mozillazine.org/about:config

  • How to save an image as a PICT resource file?

    Can someone tell me how to save an image as a PICT resource file? I'd like to make ikons in Photoshop and save them in this format, but I 'm not finding any leads. Thanks!

    If you have Resorcerer from "ancient times" it of course can handle resource forks since that's was it's goal in life.
    There are lots of icon creation apps these days.  Do a search for "icon" on macupdate.com to see what's available.  For example that search finds:
    iconXprit
    Icon Builder X

  • How do I save a password protected file without a password?

    Someone sent me a password protected file and I want to save it on my computer without the password.
    Thanks,
    Scott

    Hi Scott,
    It is not possible to save a password protected file without a password with Adobe Reader, you would require Adobe Acrobat to remove the password protection. Even with Adobe Acrobat you can only remove the security if you are aware about the password otherwise you need to contact the Author/creator of the PDF to remove the security.
    Regards,
    ~Pranav

  • How to save output image after IMAQ-FFT to the file

    When I apply IMAQ FFT on monochromatic image and display complex destination image by IMAQ WindDraw, I get picture which I am not able to save to the file. I tried various conversions from complex image to bitmap (array), but result was everytime different from that got by IMAQ WindDraw.
    I thank for any help.

    Hallo Filip,
    you cannot save Complex Image to file to be readable by other programs - see link: http://digital.ni.com/public.nsf/websearch/D557B1A79C30AD5F86256AB1006A678A?OpenDocument
    What you can do is convert Complex Image to 8-bits BMP file format and save it then. This question was answered already - see example at: http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3ECED56A4E034080020E74861&p_node=DZ52000_US&p_source=External
    Hope this helps
    Pavel

  • How to save from .ai to .png without a gap

    I created a repeating pattern. I made the artboard the exact size of the art. I zoomed in and there are no gaps around the edge. I saved it for web and devices png8 and the top has a gap with transparency showing through. When I use it as a web page background, there is a white stripe showing. I've tried twice to resave it but get the same gap.
    I'm trying to upload the two images using the camera icon but nothing happens after I select the image and click the "insert image" button. Again, I've tried twice without a different result. Please advise.
    Thank you.
    Please help.
    Kathleen

    Having a hard time with google docs, sigh. Thank you for all your help.
    From: "Kurt Gold" <[email protected]>
    To: "kathpoole" <[email protected]>
    Sent: Tuesday, May 28, 2013 1:29:21 PM
    Subject: How to save from .ai to .png without a gap
         Re: How to save from .ai to .png without a gap
    created by Kurt Gold in Illustrator - View the full discussion
    Adobe Illustrator files are not tolerated as attachments in that Adobe Illustrator forum (great, isn't it?).
    You may take a service like Google Docs to provide them.
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5359346#5359346
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5359346#5359346
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5359346#5359346. In the Actions box on the right, click the Stop Email Notifications link .
    Start a new discussion in Illustrator by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746 .

  • How to save the image in the form?

    As thread, how to save the image into a file from the pdf form - image box?
    I have Adobe Acrobat 9 Pro extended.

    Hi Sandy,
    Sorry for Delay.Could you please provide script code for the Button and in which event we want to add the code
    I want to Save the lot of images in the PDF. For that I kept Image field in the form.Here I am able to upload the images but those are not saved.
    If possible please share the details document.
    Please help me.
    Thanks,
    Ravi.

  • How can I open a PDF file without first saving the file?

    How can I open a PDF file without first having to save the file?

    How can I open a PDF file without first having to save the file?

  • How to save downloaded update installer files

    How can I locate a downloaded update installer file so I can save it and use to install on another mac without having to download all over again?  Today I downloaded updates for OS X and also for Office 2011.  The first is over 2GB and the second around 300MB.  I have installed on my Macbook Pro, but I have another 3 units to update. I live in a 3rd world country with very slow internet and it takes me days to download such files.

    Grateful for you having replied but for some reason I seem unable to open your message "Re: How to save downloaded update installer files".  Waikato99

  • [CS4]  save on a local file without  user intervention

    hey,...sorry for my english...
    i work with a other application who need to have the
    information written in the local file without an user intervention
    so...
    i would like to know if it s possible to write or rewrite on
    a local file without intervention of the user...
    whitout the ""save dialogue box" or with a managed save
    dialogue box...
    how to write in a local file without user intervention...
    i need really an answer to make real my project...
    thans for your conprehension

    hey
    thx a lot for your help ...
    if i understand well ...
    it is possible to write or rewrite in a specific folder
    who is determinated by the application folder of
    an specific AIR apllication
    who during his install give the ""authorization to
    write/rewrite /save in his specific installation foder"
    so it s possible with combination of an AIR application.....
    can you give me some information about this AIR application
    that i must build...
    some direction to ask help
    because i dont have the knowledges to do that
    what style/type of AIR application
    what charachteristics of this AIR application....
    so some information that can i use to ask help in the good
    place...
    one more time thx a lot for your help...;)

  • How to read some images from file system with webdynpro for abap?

    Hi,experts,
    I want to finish webdynpro for abap program to read some photos from file system. I may make MIMES in the webdynpro component and create photos in the MIMES, but my boss doesn't agree with me using this way. He wish me read these photos from file system.
    How to read some images from file system with webdynpro for abap?
    Thanks a lot!

    Hello Tao,
    The parameter
       icm/HTTP/file_access_<xx>
    may help you to access the pictures without any db-access.
    The following two links may help you to understand the other possibilities as well.
    The threads are covering BSP, but it should be useful for WebDynpro as well.
    /people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents
    http://help.sap.com/saphelp_sm40/helpdata/de/c4/87153a1a5b4c2de10000000a114084/content.htm
    Best regards
    Christian

  • How to save an image as PDF?

    Hi,
    I need help o how to save an Image as PDF file?? is this possible?

    Under Getting Started in the welcome window click Create PDF
    Open your image
    File>Save As...PDF
    But I am finding that there are limitations on how big the image can be. I am trying to save a 20mb jpeg to pdf in acrobat and having issues. Good luck!

  • How to save a text or file in *doc from Pages?

    How to save a text or file in *doc?

    Igor,
    Use either File > Export, or Share > Export, and choose the Word option.
    Jerry

  • How can I edit a pdf file without converting it?

    How can I edit a pdf file without converting it?

    Hi there,
    To edit a PDF file in the PDF format, you need Adobe Acrobat.
    -David

  • How to save an image to database and retreive from it.

    how to save an image retreived from an bytearray to database and retreive back the image from database....pls specify the steps and the query.

    You can use the JDBC API for database connectivity and you can use SQL to query the database.
    JDBC tutorial: http://www.google.com/search?q=jdbc+tutorial+site:sun.com
    SQL tutorial: http://www.google.com/search?q=sql+tutorial+site:w3schools.com

Maybe you are looking for

  • Switching between Primary and Standby database

    Hi, I managed to setup a standby database that is updated by the primary db either when doing a log file switch or when changing the role of the primary db to standby. Now I want to put the standby database (that was in primary role for a short perio

  • Issue printout from mail on Mac OS X 10.9

    We have a network printer Konica Bizhub C452 and I have an user when he want to print on this printer from mail under Mac OS X 10.9.2  around one time on 5 he has a error message " Mail a quitté de manière imprévue lors de l’utilisation du module pde

  • Hiding Applet Window

    Hi there! I need help on hiding applet window. I have tried using hide() method but the compiler gives deprecated warnings and ask me to refer to documentation but I dont know how to use it. Does anyone knows how to hide/minimise or whatever so that

  • Debugging Labwindows dll in teststand with CVI 9.1.1

    Is there a known problem when debugging Labwindows DLL used as Teststand Code module ( using the Labwindows CVI Adapter)? My setup includes to powersupplies with IVI instrument drivers ( Agilent 6032A and and E3634 A) a a few other instruments with n

  • SAP java connector

    I know how to make applications Java to SAP System but, I need to know how to make a SAP function module System to Java calls. Please send me steps, examples, codes, hints or libraries. ¡thanks!