I decided to create a program (mini version) of Photoshop. Everything works, but, I have:

public class PhotoshoPanel extends JPanel 

How can I get an image from a JPanel object and save it as a jpeg or png file after some action has taken place?

1 answer 1

Code snippets:

 try { // retrieve image BufferedImage bi = getMyImage(); File outputfile = new File("saved.png"); ImageIO.write(bi, "png", outputfile); } catch (IOException e) { //... } try { // retrieve image BufferedImage bi = getMyImage(); File outputfile = new File("saved.jpg"); ImageIO.write(bi, "jpg", outputfile); } catch (IOException e) { //... } try { // retrieve image BufferedImage bi = getMyImage(); File outputfile = new File("saved.gif"); ImageIO.write(bi, "gif", outputfile); } catch (IOException e) { //... } 

https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html

  • It meant - how to get the image from the finished JPanel'and on which I have already drawn something. The answer is already given. But also n atom thanks. - Razor