How do i save a resized image to a specific folder?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ImgChooser ic = new ImgChooser();
ImageIcon icon = new ImageIcon(me,"id pic");
Image img1 = icon.getImage();
Image img2 = img1.getScaledInstance(105, 105, 0);
icon.setImage(img2);
jLabel1.setIcon(icon);
}
This first code is where i get the image and resize it. Then i want the resized image to be saved in another folder. Thanks in advance
Try this...
Use
ImageIO.write()
method...static boolean ImageIO.write(RenderedImage im, String formatName, File output) throws IOException
Eg:
First transform your image into a
BufferedImage
and then useImageIO
to save the image:Where the format name is a
String
like"jpg"
,"png"
or"gif"
andoutputFile
is theFile
to save the image to.Also please note that if you are saving an image that doesn't support an alpha level (transparency) then the third parameter you pass to the
BufferedImage
constructor should be a 3 byte image like:BufferedImage.TYPE_3BYTE_BGR
Use
ImageIO.write(...)
as others have already said (+1 to them), to add here is an example for you:Reference: