Results 1 to 4 of 4
  1. #1
    hei1233212000 is offline Member
    Join Date
    Jul 2010
    Posts
    36
    Rep Power
    0

    Default output jpeg file problem

    If I draw some graphics on a JPanel, let's say a circle, can I save the graphics as a jpeg file?
    Thank you.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Java Code:
    		BufferedImage image = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_RGB);
    		panel.paintAll(image.createGraphics());
    		ImageIO.write(image, "jpg", new File("panel.jpg"));
    or you are painting directly on a bufferedeimage instead of a jpanel and use drawImage in your paint/paintComponent method.

    An image can be saved with the ImageIO.write method!

  3. #3
    hei1233212000 is offline Member
    Join Date
    Jul 2010
    Posts
    36
    Rep Power
    0

    Default

    Thank you eRaaaa :)

  4. #4
    hei1233212000 is offline Member
    Join Date
    Jul 2010
    Posts
    36
    Rep Power
    0

    Default

    I have one more question.
    Is it possible to display a jpg image on a JPanel without using JLabel?
    Thank you

Similar Threads

  1. Problem while redirecting script output to a file using java
    By umapathy_sekar in forum Advanced Java
    Replies: 4
    Last Post: 11-09-2010, 09:33 AM
  2. Printing JPEG file using java
    By venkateshcoolmoon in forum Advanced Java
    Replies: 2
    Last Post: 02-18-2010, 05:50 AM
  3. problem with output of jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 04:00 PM
  4. how to include restart merkers in a JPEG file
    By ananta_javaforums001 in forum Networking
    Replies: 0
    Last Post: 04-09-2009, 03:29 PM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 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
  •