import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
/*
* FrmImageIO.java
*
* Created on 21. April 2003, 15:07
*/
/**
*
* @author Administrator
*/
public class FrmImageIO extends javax.swing.JFrame implements ActionListener {
private JButton jbtn;
private Image img;
private BufferedImage buffimg;
private Graphics graph;
/** Creates new form FrmImageIO */
public FrmImageIO() {
initComponents();
this.setSize(new Dimension(512,384));
Container cont = this.getContentPane();
cont.setLayout(new GridLayout(25,20));
jbtn = new JButton("Write IMAGE!");
jbtn.addActionListener(this);
cont.add(jbtn);
img = this.getToolkit().getImage("c:\\javadev\\Beispiel.jpg");
MediaTracker mt = new MediaTracker(this);
mt.addImage(img,0);
try{
mt.waitForAll();
}catch(InterruptedException ie){
//nix
}
buffimg = new BufferedImage(283,212,BufferedImage.TYPE_INT_RGB);
//Dimensionen Meines Testbildes (w,h)
graph = buffimg.createGraphics();
graph.drawImage(img,0,0,null);
//TEST
graph.drawLine(0,0,100,100);
//TEST
repaint();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
pack();
}//GEN-END:initComponents
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new FrmImageIO().show();
}
public void paint(Graphics g){
super.paint(g);
if(img!=null){
g.drawImage(img,25,50,this);
}
}
public void writeIMG(String fileName){
try{
ImageIO.write(buffimg,"JPEG",new File("c:\\javadev\\"+fileName));
}catch(IOException ioe){
//nix
}
}
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
System.out.println("Click!");
if(img!=null){
writeIMG("MyTestFile.jpg");
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}