JavaFX [1.3] – Save As Image


JavaFX – Save As Image code updated to be compatible with JavaFX 1.3
Please refer to JavaFX13Utils.fx for more information. You will need to update only if you are using internal APIs as mentioned in this forum thread.

For Applet mode, click on above image

For standalone mode

Try it out and let me know feedback

About these ads

About Rakesh Menon
-

11 Responses to JavaFX [1.3] – Save As Image

  1. That’s great!

    I think this sample:

    http://javafx.com/samples/PhotoEffects/index.html

    will be real world usage if we add save as image and upload image. Maybe more effects

  2. Pingback: uberVU - social comments

  3. Pingback: JavaFX – Save As Image « Java, JavaFX and beyond…

  4. Pingback: JavaFX links of the week, May 2 // JavaFX News, Demos and Insight // FX Experience

  5. Kishore says:

    I am still disappointed, the code to save a Node, or change a Node to BufferedImage is still not through a proper API, these work arounds are not guaranteed will support in future version’s. that too, for saving a single Node we have to save the complete Scene, there should be a proper API level support for converting any Node to BufferedImage,
    something straight and simple like

    Node.getBufferedImage()
    OR
    Graphics mybufferedImageGraphics = myBufferedImage.getGraphics();
    Node.paint(Graphics mybufferedImageGraphics)

  6. Rakesh Menon says:

    @Kishore I agree.. But the APIs are designed not to expose any of AWT APIs (Graphics, BufferedImage etc). This is to ensure that we can provide other Toolkit implementation (such as Prism). So I think for now its not feasible to provide any such public APIs. Btw, the above workaround doesn’t save complete Scene, it only saves the Node which is passed to the nodeToImage function.

  7. Kishore says:

    @Rakesh,

    Number of lines of code to convert one Node to BufferedImage was not very nice. Thats the reason I asked for that functionality, atleast some Util methods directly from JAVAFX API which do this work.

    Thankyou Rakesh, will try this in my application.

  8. Kishore says:

    For those who want a Transparent Buffered Image:

    If you want to transparent Image, comment out the following two lines in the “JavaFX13Utils.fx”

    Line 93 and 94
    //g2.setPaint(java.awt.Color.WHITE);
    //g2.fillRect(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight());

  9. John Sandlin says:

    I’m trying to implement the print function using your print utils. I’m getting an error:

    Printer not activated, error code -20

    This is with JavaFX 1.3 and your JavaFX13Utils.fx and PrintUtils.java.

  10. John Sandlin says:

    I created a project for your SaveAsImage demo and compiled your code. Then I changed it to actually print rather than save. The exception I got shows the wrong printer. Quicken installs a PDF printer, which PrintUtils grabbed instead of the default printer as selected in the dialog box.

    PRINTING…
    Got PrintService: Quicken PDF Printer
    Exception in thread “AWT-EventQueue-0″ javax.print.PrintException: java.awt.print.PrinterException: The data area passed to a system call is too small.

    Is that from the PrintServices[0].createPrintJob ? Is the 0 the first device regardless which printer was selected? Somehow it’s trying to print to the Quicken PDF Printer service.

    jbs

  11. John Sandlin says:

    Follow up note…: I did try changing the zero to another value… and got a different printer device (one that works). I found a snippet of code that uses the printer dialog to choose a device. It uses javax.print.ServiceUI.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 45 other followers

%d bloggers like this: