How to save JFrame image as png format?

hello all..
i've encountered some problem while i using my Java3D to load my VRML file & save it in png format.
i've loaded the VRML file in my Java 3D and display it on the JFrame.
now, i want to save the image as PNG format, but i can't save the image, but just save the background & canvas.
here's my code:
Button button = new Button("Save image");
button.addActionListener( new ActionListener()
public void actionPerformed(ActionEvent event)
RenderedImage image = myCreateImage();
// Write generated image to a file
try {
FileDialog fd = new FileDialog(f, "Save as PNG", FileDialog.SAVE);
fd.show();
String name= fd.getFile();
// Save as PNG
ImageIO.write((RenderedImage)image, "png", new File(name));
catch (IOException e) {}
content_pane.add(button, BorderLayout.SOUTH);
try
FileReader fr = new FileReader( "TS.java" );
BufferedReader br = new BufferedReader(fr);
catch(Exception e) {}
pack();
setLocationRelativeTo( null );
setSize(800, 600);
setLocation(0, 40);
setVisible(true);
setBackground(Color.white);
public RenderedImage myCreateImage() {
int width = 800;
int height = 600;
// Create a buffered image in which to draw
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.dispose();
return bufferedImage;
private void loadFile(String file) {
int flag = VRML97Loader.LOAD_ALL;
if(staticLoad)
flag &= ~VRML97Loader.LOAD_BEHAVIOR_NODES;
VRML97Loader loader = new VRML97Loader(flag);
// if the file is a directory, ignore it
File f = new File(file);
if(f.exists() && !f.isFile()) {
System.out.println("Can't load directories specified");
System.exit(1);
URL url = null;
Scene scene = null;
try {
if(url != null)
scene = loader.load(url);
else
scene = loader.load("vrml/fish.wrl");
} catch(Exception e) {
System.out.println("Exception loading URL:" + e);
e.printStackTrace();
System.exit(0);
urlLabel.setText("File " + file);
if (scene != null) {
// get the scene group
sceneGroup = scene.getSceneGroup();
sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
sceneGroup.compile();
// add the scene group to the scene
examineGroup.addChild(sceneGroup);
// now that the scene group is "live" we can inquire the bounds
setViewpoint();
// setupBackground(scene);
// setupLighting(scene);

Your g2d is doring nothing!
Indent your code.
class{
   type data1;
   type data2;
   type method(){
       statement;
        clause{
           statement;

Similar Messages

  • How to save an image in png format?

    I have modified an image with J2ME and stored this into a byte array, now how can I save this byte array like a png Image??? or anyone format. Class Image have not some method for this task.

    you can use rms to save your image. Try to learn it on http://java.sun.com/javame/reference/apis/jsr037/javax/microedition/rms/RecordStore.html

  • How to save an image in different format

    i want to save an image in different format (as .jpg ,.gif, .tiff, .png, .bmp) using save dialog box , where format should come in drop box menu "Save as type" in save dialoge box.what to do.???????plz any one suggest me .........

    alok_raj wrote:
    i want to save an image in different format (as .jpg ,.gif, .tiff, .png, .bmp) using save dialog box , where format should come in drop box menu "Save as type" in save dialoge box.what to do.???????plz any one suggest me .........1) Spell words properly. That word is 'please'.
    2) Fix your sticky keyboard for the '?' and '.' keys. Only one of those characters is generally needed to denote a question or the end of a sentence. Two or more often denotes a dweeb.
    I might come back to your question later, assuming I can actually bare looking at that mess long enough to figure out what you want.

  • How to export full image in PNG format lying inside a smaller sized rectangle?

    Hi
    In my own created extension for adobe inDesign using CS Extension builder 1.5, I am trying to export a page item lying inside a rectangle frame longer than frame height. Full image is not exported but it gets cropped which is of the rectangle height. I need to get full image exported in PNG format. The item can be text/image/drawing/or group of multiple items lying inside a rectangle frame.
    Sometimes the correct image is exported although the rectangle frame size is smaller than the inside image/item. Following is the code I’m using to export the page item.
    var targetItem:PageItem = pageItem.allPageItems[0];
    targetItem.exportFile(ExportFormat.PNG_FORMAT, targetFile, false);
    Can anybody help me out?
    Thanks and best regards
    Sal

    the answer is at : http://forums.adobe.com/thread/1060138

  • 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 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 a invoice in Word Format

    Dear  Sd Gurus
    Please tell how to save a invoice in any format like word format other than the printed stationery .This saved document will be used for mailing to the customer.
    No interface with internet or EDI .
    Hope for a reply soon
    Satish Kullu

    Hi Satish,
    First, your SAP system must be configure by the basis people in order for you to send an external mail. 
    Whether it can send pdf or other file format will depends on the Mail Server you are using.
    The basis people must also maintain the conversion parameters so that SAP knows how to convert the billing documents to be send as a pdf file or other desired format specified by your company.
    Finally, you have define the IMG in Maintain Output Determination for Billing Documents (Output type MAIL) 
      Reward points if this helps.
    Regards
    Karan

  • 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 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

  • 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 layout with ALV Pivot format

    Hi
    In ALV report I have  25 fields but I want to use 10 fields out of 25 fields in Pivot Table. My problem is how to save this layout with Pivot format for on going use. At every time execution of report I need not required to set  Pivot Table.
    Please help me.
    -Sanjay

    Hi,
    Are you using FM REUSE_ALV_GRID_DISPLAY? If yes, then pass 'X' to the parameter I_SAVE while calling the fm.
    if you are using Object Oriented ALV, then call the below method before calling the method for display
    DATA : gr_layout TYPE REF TO cl_salv_layout,
           gr_layout_key TYPE salv_s_layout_key.
    CALL METHOD gr_functions->set_all
      EXPORTING
        value  = IF_SALV_C_BOOL_SAP=>TRUE.
      MOVE sy-repid TO gr_layout_key-report.
      CALL METHOD gr_table->get_layout
        RECEIVING
          value = gr_layout.
      CALL METHOD gr_layout->set_key
        EXPORTING
          value = gr_layout_key.
      CALL METHOD gr_layout->set_save_restriction
        EXPORTING
          value = if_salv_c_layout=>restrict_none.
      CALL METHOD gr_layout->set_default
        EXPORTING
          value = if_salv_c_bool_sap=>true.
    Regards
    Vinod
    Edited by: Vinod Kumar on Jul 2, 2010 3:40 PM
    Edited by: Vinod Kumar on Jul 2, 2010 4:43 PM

  • How to save an image from canvas to jpeg2000 format?

    good day! i would like some help about jj2000. i wish to save an image from canvas to a jpeg2000 format file. how will i do it using the jj2000? i just need to save it to a file.
    please help!!!
    thank you in advance!
    lrds

    I am not familiar with Jpeg2000, but the easiest way I've found to go from Java to a JPeg file is with Java Adavanced Imaging (JAI) package from Sun. Take a look at it and see if it meets your requirements.

  • How to save and retrieve jpg/gif format image in db2

    Here am facing problem to insert jpg/gif format image in my database. And at the same time i would like to know how to retrieve that and how to display that image in my html page. So please help me in this matter.

    In future JDBC questions should be posted into the JDBC Forum

  • How to save an image into the RTF Viewer

    RTF Viewer.
    The current problem that I have with the RTFViewer is that the RTFEditor allows for images to be inserted but on save the images get lost and no information on the images are saved.

    daregazi wrote:
    I have posted my problem before, nobody replied so I ask again if anybody has any solution??
    I want to save an image, which I created before from a physical file and did some bit-level manipulation, into the same or a new (doesn't matter) physical file (say in png format). But I do not know how to do it. I have tried the FileConnection API and OutputStream and then the method write() to write the byte array, rather this does not solve my problem. I need something like corresponding to J2SE ImageIO.write(image,null) function. Any Idea??
    please.....I don't think it's possible in a midlet. You'll have to save the data as a byte[] to a RecordStore and then convert it back again if you want the midlet to redisplay it.

  • How to save an image into an image file?

    I have posted my problem before, nobody replied so I ask again if anybody has any solution??
    I want to save an image, which I created before from a physical file and did some bit-level manipulation, into the same or a new (doesn't matter) physical file (say in png format). But I do not know how to do it. I have tried the FileConnection API and OutputStream and then the method write() to write the byte array, rather this does not solve my problem. I need something like corresponding to J2SE ImageIO.write(image,null) function. Any Idea??
    please.....

    daregazi wrote:
    I have posted my problem before, nobody replied so I ask again if anybody has any solution??
    I want to save an image, which I created before from a physical file and did some bit-level manipulation, into the same or a new (doesn't matter) physical file (say in png format). But I do not know how to do it. I have tried the FileConnection API and OutputStream and then the method write() to write the byte array, rather this does not solve my problem. I need something like corresponding to J2SE ImageIO.write(image,null) function. Any Idea??
    please.....I don't think it's possible in a midlet. You'll have to save the data as a byte[] to a RecordStore and then convert it back again if you want the midlet to redisplay it.

Maybe you are looking for