0% found this document useful (0 votes)
37 views

Save Image Java

This document provides code snippets for saving images to files and reading images from files in Java. It shows how to save a BufferedImage to a file using ImageIO, specifying the file extension. It also demonstrates how to read an image file back into a BufferedImage using ImageIO, and then display that image in a JLabel within a JFrame window to view the image.

Uploaded by

PPP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Save Image Java

This document provides code snippets for saving images to files and reading images from files in Java. It shows how to save a BufferedImage to a file using ImageIO, specifying the file extension. It also demonstrates how to read an image file back into a BufferedImage using ImageIO, and then display that image in a JLabel within a JFrame window to view the image.

Uploaded by

PPP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

you can save image

private static void save(BufferedImage image, String ext) {

File file = new File(fileName + "." + ext);


BufferedImage image = toBufferedImage(file);
try {
ImageIO.write(image, ext, file); // ignore returned boolean
} catch(IOException e) {
System.out.println("Write error for " + file.getPath() +
": " + e.getMessage());
}
}

and read image from disk and show into label as

File file = new File("image.gif");


image = ImageIO.read(file);
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy