summaryrefslogtreecommitdiff
path: root/src/aufgaben/b20160425
diff options
context:
space:
mode:
Diffstat (limited to 'src/aufgaben/b20160425')
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe1.java73
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe2.java82
-rwxr-xr-xsrc/aufgaben/b20160425/Aufgabe3.java121
3 files changed, 276 insertions, 0 deletions
diff --git a/src/aufgaben/b20160425/Aufgabe1.java b/src/aufgaben/b20160425/Aufgabe1.java
new file mode 100755
index 0000000..9f90600
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe1.java
@@ -0,0 +1,73 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+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 BufferedImage image, todraw;
+ private Color[][] pixels;
+
+ public Aufgabe1() {
+ name = "Spiegelung";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(image != null)
+ g.drawImage(todraw, 0, 100, 500, 300, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ System.out.println("test");
+ pixels = new Color[width][height];
+ try {
+ image = ImageIO.read(new File("kraehne2.jpg"));
+ todraw = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = image.getWidth()-1, width = image.getWidth(); x>0; x--) {
+ for(int y = 0, height = image.getHeight(); y<height; y++) {
+ Color c = new Color(image.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ todraw.setRGB(image.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe2.java b/src/aufgaben/b20160425/Aufgabe2.java
new file mode 100755
index 0000000..5ab54a7
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe2.java
@@ -0,0 +1,82 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe2 extends Aufgabe {
+
+ private final int width = 1000, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage source, vertical, horizontal, both;
+ private Color[][] pixels;
+
+ public Aufgabe2() {
+ name = "Spiegelung 2";
+ this.setSize(width, height);
+ this.setTitle(name);
+ this.addWindowListener(
+ new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ System.out.println("close");
+ done = true;
+ }
+ }
+ );
+ }
+
+ @Override
+ public boolean done() {
+ return done;
+ }
+
+ public void paint(Graphics g) {
+ if(source != null)
+ g.drawImage(source, 0, 0, 500, 500, this);
+ if(vertical != null)
+ g.drawImage(vertical, 500, 0, 250, 250, this);
+ if(horizontal != null)
+ g.drawImage(horizontal, 750, 0, 250, 250, this);
+ if(both != null)
+ g.drawImage(both, 500, 250, 250, 250, this);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void init() {
+ pixels = new Color[width][height];
+ try {
+ source = ImageIO.read(new File("kraehne2.jpg"));
+ vertical = ImageIO.read(new File("kraehne2.jpg"));
+ horizontal = ImageIO.read(new File("kraehne2.jpg"));
+ both = ImageIO.read(new File("kraehne2.jpg"));
+ for(int x = 0, width = source.getWidth(); x<width; x++) {
+ for(int y = 0, height = source.getHeight(); y<height; y++) {
+ Color c = new Color(source.getRGB(x, y));
+ int h = (int)(((double)(c.getRed()+c.getGreen()+c.getBlue())/765)*255);
+ vertical.setRGB(source.getWidth()-x-1, y, new Color(h, h, h).getRGB());
+ horizontal.setRGB(x, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ both.setRGB(source.getWidth()-x-1, source.getHeight()-1-y, new Color(h, h, h).getRGB());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/aufgaben/b20160425/Aufgabe3.java b/src/aufgaben/b20160425/Aufgabe3.java
new file mode 100755
index 0000000..2a2b242
--- /dev/null
+++ b/src/aufgaben/b20160425/Aufgabe3.java
@@ -0,0 +1,121 @@
+package aufgaben.b20160425;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JPanel;
+import javax.swing.JSpinner;
+import javax.swing.SpinnerNumberModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import aufgaben.Aufgabe;
+import misc.Utils;
+
+public class Aufgabe3 extends Aufgabe {
+
+ private final int width = 500, height = 500;
+ private boolean done = false;
+ private String name;
+ private BufferedImage image, todraw;
+ private JPanel panel;
+ private JSpinner spinner;
+
+ public Aufgabe3() {
+ name = "Interpolation";
+ 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() {
+ panel = new JPanel(){
+ public void paint(Graphics g) {
+ if(todraw != null)
+ g.drawImage(todraw, 0, 0, this.getWidth(), this.getHeight(), this);
+ }
+ };
+ panel.setBounds(0, 100, width, height-100);
+ spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
+ spinner.setBounds(100, 50, 100, 20);
+ spinner.addChangeListener(new ChangeListener() {
+ public void stateChanged(ChangeEvent e) {
+ for(int x = 0; x<image.getWidth(); x++) {
+ for(int y = 0; y<image.getHeight(); y++) {
+ todraw.setRGB(x, y, getDurchschnitt(image, x, y, (int)spinner.getValue()).getRGB());
+ }
+ }
+ panel.repaint();
+ }
+ });
+ try {
+ image = ImageIO.read(new File("title.png"));
+ todraw = ImageIO.read(new File("title.png"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ this.add(panel);
+ this.add(spinner);
+ }
+
+ private int getGrayValueImg(int x, int y) {
+ if(image == null) return -1;
+ Color c = new Color(image.getRGB(x, y));
+ if(c.getRed() == c.getGreen() && c.getRed() == c.getBlue())
+ return c.getRed();
+ return -1;
+ }
+
+ private void setGrayValueImgProc(int x, int y, int gray) {
+ if(image == null)
+ System.out.println("err");
+ image.setRGB(x, y, new Color(gray, gray, gray).getRGB());
+ }
+
+ private Color getDurchschnitt(BufferedImage image, int x, int y, int r) {
+ Color color;
+ int[] colori = new int[3];
+ int absoluteX = 0, absoluteY = 0, c = 0;
+ for(int x1 = (-1)*r; x1<=r; x1++) {
+ for(int y1 = (-1)*r; y1<=r; y1++) {
+ absoluteX = x+x1;
+ absoluteY = y+y1;
+ if(absoluteX >= 0 && absoluteX < image.getWidth() && absoluteY >= 0 && absoluteY < image.getHeight()) {
+ color = new Color(image.getRGB(absoluteX, absoluteY));
+ colori[0] += color.getRed();
+ colori[1] += color.getGreen();
+ colori[2] += color.getBlue();
+ c++;
+ }
+ }
+ }
+ return new Color(colori[0]/c, colori[1]/c, colori[2]/c);
+ }
+
+}