Results 1 to 2 of 2
  1. #1
    Wise girl is offline Member
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

    Default Problem with saving image to a file

    I wrote this code, but it does not save the image just blank page. PLEASE HELP


    import java.awt.Graphics2D;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;




    class SaveButtonAction implements ActionListener {


    DataContainer dcRef = null;
    ActionContainer ac = null;
    DrawingCanvas drawingPanel = null;
    String cmd = null;
    JFrame f = new JFrame();


    SaveButtonAction(DataContainer dc, ActionContainer ac, DrawingCanvas drawingPanel) {

    dcRef = dc;
    this.ac = ac;
    this.drawingPanel = drawingPanel;

    }


    public void actionPerformed(ActionEvent e) {
    System.out.println("[savebutton] pushed");

    //sets up the action similar to plot
    drawingPanel.plotPie(cmd);


    //set up graphics 2d

    try {

    BufferedImage image =
    new BufferedImage( 120, 120, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = image.createGraphics();
    f.paint( graphics2D );
    graphics2D.dispose();
    ImageIO.write(image, "png", new File("AA.png"));
    } catch (Exception ex) {
    ex.printStackTrace();
    }

    //call the drawpanel.repaint();

    drawingPanel.repaint();
    }

    }

    public class SaveButton extends GButton {

    SaveButton(String name, DataContainer dcRef, ActionContainer ac, DrawingCanvas drawingPanel) {
    super(name, dcRef);

    SaveButtonAction action = new SaveButtonAction(dcRef, ac, drawingPanel);
    addActionListener(action);
    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Problem with saving image to a file

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    Nothing whatsoever to do with Applets. Moving to Java 2D.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Saving a lattice into an image file
    By jim93 in forum New To Java
    Replies: 1
    Last Post: 09-04-2011, 04:47 AM
  2. how to extract specific data from image file and saving in to database
    By Balasubrahmanyam in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-27-2011, 03:19 PM
  3. Need help with saving an image
    By Manifesto32 in forum New To Java
    Replies: 2
    Last Post: 04-01-2011, 05:35 AM
  4. problem in saving file
    By jogendar in forum Advanced Java
    Replies: 2
    Last Post: 01-23-2010, 05:28 PM
  5. Problem Saving a file
    By GraemeH in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •