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?
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?
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
Source: https://ru.stackoverflow.com/questions/589487/
All Articles