import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageSpeichernClass extends JFrame {
private static final long serialVersionUID = 1L;
JPanel panel;
JLabel label;
ImageIcon icon;
BufferedImage image;
public ImageSpeichernClass() {
File file = new File("vorher.jpg");
try {
this.image = ImageIO.read(file);
} catch (IOException ex) {
ex.printStackTrace();
}
int imageBreite = image.getWidth();
int imageHoehe = image.getHeight();
icon = new ImageIcon(image);
label = new JLabel(icon);
label.setBorder(new LineBorder(Color.WHITE));
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(Color.DARK_GRAY);
panel.add(label, BorderLayout.CENTER);
getContentPane().add(panel);
setSize(imageBreite + 100, imageHoehe + 100);
try {
FileOutputStream fos = new FileOutputStream(new File("nachher.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
param.setQuality(0.001F, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(image);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String args[]) {
new ImageSpeichernClass();
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageSpeichernClass extends JFrame {
private static final long serialVersionUID = 1L;
JPanel panel;
JLabel label;
ImageIcon icon;
BufferedImage image;
public ImageSpeichernClass() {
File file = new File("vorher.jpg");
try {
this.image = ImageIO.read(file);
} catch (IOException ex) {
ex.printStackTrace();
}
int imageBreite = image.getWidth();
int imageHoehe = image.getHeight();
icon = new ImageIcon(image);
label = new JLabel(icon);
label.setBorder(new LineBorder(Color.WHITE));
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(Color.DARK_GRAY);
panel.add(label, BorderLayout.CENTER);
getContentPane().add(panel);
setSize(imageBreite + 100, imageHoehe + 100);
try {
FileOutputStream fos = new FileOutputStream(new File("nachher.jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
param.setQuality(0.001F, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(image);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
public static void main(String args[]) {
new ImageSpeichernClass();
}
}