package aufgaben.imageio; import java.awt.Color; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import javax.imageio.ImageIO; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; import aufgaben.Aufgabe; import misc.Utils; public class Aufgabe1 extends Aufgabe { private final int width = 500, height = 500; private boolean done = false; private String name; private JPanel panel; private JTextField inPath, outPath; private JButton readButton, writeButton; private BufferedImage bild; public Aufgabe1() { name = "Lesen Speichern"; this.setSize(width, height); this.setTitle(name); this.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("close"); done = true; } } ); this.setLayout(null); } @Override public boolean done() { return done; } @Override public String getName() { return name; } @Override public void init() { inPath = new JTextField(); inPath.setBounds(50, 50, 200, 20); outPath = new JTextField(); outPath.setBounds(50, 80, 200, 20); readButton = new JButton("Lesen"); readButton.setBounds(260, 50, 100, 20); readButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { bild = readImage(new File(inPath.getText())); /* try { bild = ImageIO.read(new File("title.png")); } catch (IOException e) { e.printStackTrace(); } */ panel.repaint(); } }); writeButton = new JButton("Schreiben"); writeButton.setBounds(260, 80, 100, 20); writeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { writeImage(new File(outPath.getText()), bild); } }); panel = new JPanel() { public void paint(Graphics g) { if(bild != null) g.drawImage(bild, 0, 0, 500, 390, this); } }; panel.setBounds(0, 110, 500, 390); this.add(inPath); this.add(outPath); this.add(readButton); this.add(writeButton); this.add(panel); this.repaint(); } private BufferedImage getGreyImage(BufferedImage i) { BufferedImage image = new BufferedImage(i.getWidth(), i.getHeight(), i.getType()); for(int x = 0, width = i.getWidth(); x> 24) & 0xFF), (byte) ((a >> 16) & 0xFF), (byte) ((a >> 8) & 0xFF), (byte) (a & 0xFF) }; } }