1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
JFrame jFrame = new JFrame("Main");
jFrame.setLayout(null);
jFrame.setBounds(100,100,320,225);
jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
BufferedImage bufferedImage = new BufferedImage(320,200,BufferedImage.TYPE_3BYTE_BGR);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.setBackground(new Color(0xff,0xff,0x00));
graphics2D.setColor(Color.RED);
graphics2D.drawString("C'est une image jpg",0,20);
try {
JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(new FileOutputStream("img.jpg"));
codec.encode(bufferedImage);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ImageFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JLabel label = new JLabel(new ImageIcon(bufferedImage));
label.setBounds(0,0,320,200);
jFrame.add(label);
jFrame.setVisible(true); |
Partager