From: git Date: Sun, 2 Jul 2017 21:38:10 +0000 (+0200) Subject: updated the revision of b&W bug and display bug X-Git-Url: http://git.risc.jku.at/gitweb/?a=commitdiff_plain;h=9313c7fb5551bb015bfd3bcd7a1e00557e0b9ade;p=ipau%2FColorBlackWhiteConversion.git updated the revision of b&W bug and display bug --- diff --git a/Revise_Version/BlackandWhite.java b/Revise_Version/BlackandWhite.java new file mode 100644 index 0000000..c94a394 --- /dev/null +++ b/Revise_Version/BlackandWhite.java @@ -0,0 +1,59 @@ +import java.awt.*; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.WritableRaster; + +public class BlackandWhite { + + private BufferedImage image; + int width; + int height; + + /*public void BlackandWhite() + { + image = null; + width = 0; + height = 0; + }*/ + + static BufferedImage deepCopy(BufferedImage bi) { + ColorModel cm = bi.getColorModel(); + boolean isAlphaPremultiplied = cm.isAlphaPremultiplied(); + WritableRaster raster = bi.copyData(null); + return new BufferedImage(cm, raster, isAlphaPremultiplied, null); + } + + public BufferedImage Black_and_White(BufferedImage input_image) { + + try { + image = deepCopy(input_image); + + width = image.getWidth(); + height = image.getHeight(); + + for(int i=0; i 128){ + newColor = new Color(255,255,255); + }else{ + newColor = new Color(0,0,0); + } + + image.setRGB(j,i,newColor.getRGB()); + } + } + } catch (Exception e) {} + + return image; + } +} \ No newline at end of file diff --git a/Revise_Version/ColorBlackWhiteConversionGUI.java b/Revise_Version/ColorBlackWhiteConversionGUI.java new file mode 100644 index 0000000..376998b --- /dev/null +++ b/Revise_Version/ColorBlackWhiteConversionGUI.java @@ -0,0 +1,319 @@ +import java.awt.*; +import java.awt.event.*; + +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.image.BufferedImage; +import java.util.*; + +public class ColorBlackWhiteConversionGUI +{ + public BufferedImage input_image; + //private BufferedImage temp_image; + public BufferedImage output_image; + + //for GUI + private JFrame frame; + private JPanel Input; + + private JLabel Jimage_input; + private JLabel Jimage_output; + private JPanel Output; + private String[] name; + private int att[][]; + private ArrayList GUIComponent; + private String userinput = ""; + + boolean occupied = false; + boolean saved = false; + + ColorBlackWhiteConversionGUI() + { + int fill[] = { GridBagConstraints.BOTH, + GridBagConstraints.VERTICAL, + GridBagConstraints.HORIZONTAL, + GridBagConstraints.NONE}; + + int anchor[] = {GridBagConstraints.CENTER, + GridBagConstraints.EAST, + GridBagConstraints.SOUTHEAST, + GridBagConstraints.SOUTH, + GridBagConstraints.SOUTHWEST, + GridBagConstraints.WEST, + GridBagConstraints.NORTHWEST, + GridBagConstraints.NORTH, + GridBagConstraints.NORTHEAST}; + + String n[] = { "Input:", + "Output:", + "hint...", + "Load", + "BW", + "Gray", + "Save", + "Quit"}; + + name = n; + + //x, y, width, height, weight-x, weight-y, GridBagConstraints.fill, GridBagConstraints.anchor + int a[][] = {{0, 0, 1, 1, 0, 0, fill[3], anchor[5]}, //input (word) + {9, 0, 1, 1, 0, 0, fill[3], anchor[5]}, //output (word) + {0, 11, 7, 1, 0, 0, fill[3], anchor[5]}, //hint... (word) + + //Image field + {0, 1, 4, 8, 0, 0, fill[3], anchor[5]}, //input image + {9, 1, 4, 8, 0, 0, fill[3], anchor[1]}, //output image + + //Buttons + {0, 10, 1, 1, 0, 0, fill[3], anchor[0]}, //Load file button + {6, 6, 1, 1, 0, 0, fill[3], anchor[0]}, //Black and White button + {6, 7, 1, 1, 0, 0, fill[3], anchor[0]}, //Gray Scale button + {9, 10, 1, 1, 0, 0, fill[3], anchor[0]}, //Save file button + {9, 11, 1, 1, 0, 0, fill[2], anchor[0]}, //Quit button + + //Text field + {1, 10, 3, 1, 0, 0, fill[2], anchor[0]}, //Load file text + {10, 10, 3, 1, 0, 0, fill[2], anchor[0]} //Save file text + }; + + att = a; + + frame = new JFrame(); + frame.setTitle("Color Black White Conversion"); + frame.setSize(1200, 500); + frame.setLayout(new GridBagLayout()); + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + Output = new JPanel(); + Input = new JPanel(); + Input.setBackground(Color.RED); + Output.setBackground(Color.WHITE); + + GUIComponent = new ArrayList(15); + } + + public void run() + { + for (int i=0; i<3; i++) + { + JLabel nLabel = new JLabel(name[i]); + GUIComponent.add(nLabel); + } + + Jimage_input = new JLabel(new ImageIcon(input_image)); // put input_Image into label + Input.add(Jimage_input); + GUIComponent.add(Input); + + Jimage_output = new JLabel(new ImageIcon(output_image)); //put output_Image into label + Output.add(Jimage_output); + GUIComponent.add(Output); + + //add Buttons + for (int k=3; k