DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005

    Probelm with saving Jpanel graphics to jpeg


    I have a problem about saving myPanel (extends Jpanel) graphic object to jpeg.
    I is very strange, because on the screen every thing looks ok, and when I save
    the graphics object to jpeg the saved image contains the picture of other controls
    which are not belongs to that panel but exists on the same internalframe, usually the button what is starting the saving procedure in the top left corner

    and if the panel is on a scrollpane, the picture contains the panel's drwaings twice or more? usually with fragments of the panel's picture?

    If I execure the saving procedure from the constructor of the window (internalframe)
    the active control is not appears on the saved image,
    When I am using a panel in the scrollpane, when the panel has the same size as the scrollpane, so the scrollbars are not visible, then the saved picture doesn't contains fragments !

    Does anybody have any idea about to save always the same picture from a panel
    what I can see? (jdk 1.4 and 1.5 too)

    Thank you very much in advance !

    used code to save image:
    public void saveComponent(genPanel c,String filename)
    int w = c.getWidth();
    int h = c.getHeight();

    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.clearRect(0, 0, w, h );

    ImageIO.write(bi, "jpg", new File(filename+".jpg"));
    catch(IOException ioe)
    System.err.println("write: " + ioe.getMessage());

  2. #2
    Join Date
    Nov 2004

    A GifEncoder ?

    I have this GifOutputStream class that saves a Java Image object,
    regardless of how it was made/where it came from. Maybe you can use it.
    Attached Files Attached Files
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.