My progress for conversion by ChingYi
authorgit <wangtsaichang@gmail.com>
Fri, 23 Jun 2017 16:55:09 +0000 (18:55 +0200)
committergit <wangtsaichang@gmail.com>
Fri, 23 Jun 2017 16:55:09 +0000 (18:55 +0200)
Conversion_CYC/BlackandWhite.java [new file with mode: 0644]
Conversion_CYC/GrayScale.java [new file with mode: 0644]
Conversion_CYC/blackandwhite.jpg [new file with mode: 0644]
Conversion_CYC/grayscale.jpg [new file with mode: 0644]
Conversion_CYC/test.jpg [new file with mode: 0644]

diff --git a/Conversion_CYC/BlackandWhite.java b/Conversion_CYC/BlackandWhite.java
new file mode 100644 (file)
index 0000000..6e7ae12
--- /dev/null
@@ -0,0 +1,57 @@
+import java.awt.*;
+import java.awt.image.BufferedImage;
+
+import java.io.*;
+
+import javax.imageio.ImageIO;
+import javax.swing.JFrame;
+
+public class BlackandWhite {
+
+   BufferedImage  image;
+   int width;
+   int height;
+   
+   public BlackandWhite() {
+        
+      try {
+         File input = new File("test.jpg");
+         image = ImageIO.read(input);
+         width = image.getWidth();
+         height = image.getHeight();
+         
+         for(int i=0; i<height; i++){
+         
+            for(int j=0; j<width; j++){
+            
+               Color c = new Color(image.getRGB(j, i));
+               
+               int red = (int)c.getRed();
+               int green = (int)c.getGreen();
+               int blue = (int)c.getBlue();
+               int average = (red+green+blue) / 3;
+               Color newColor;
+             
+               if (average < 128){
+                   newColor = new Color(255,255,255);
+
+               }else{
+                   newColor = new Color(0,0,0);
+
+               }
+               
+               image.setRGB(j,i,newColor.getRGB());
+            }
+         }
+         
+         File ouptut = new File("blackandwhite.jpg");
+         ImageIO.write(image, "jpg", ouptut);
+         
+      } catch (Exception e) {}
+   }
+   
+   static public void main(String args[]) throws Exception 
+   {
+          BlackandWhite obj = new BlackandWhite();
+   }
+}
\ No newline at end of file
diff --git a/Conversion_CYC/GrayScale.java b/Conversion_CYC/GrayScale.java
new file mode 100644 (file)
index 0000000..2250eda
--- /dev/null
@@ -0,0 +1,47 @@
+import java.awt.*;
+import java.awt.image.BufferedImage;
+
+import java.io.*;
+
+import javax.imageio.ImageIO;
+import javax.swing.JFrame;
+
+public class GrayScale {
+
+   BufferedImage  image;
+   int width;
+   int height;
+   
+   public GrayScale() {
+   
+      try {
+         File input = new File("test.jpg");
+         image = ImageIO.read(input);
+         width = image.getWidth();
+         height = image.getHeight();
+         
+         for(int i=0; i<height; i++){
+         
+            for(int j=0; j<width; j++){
+            
+               Color c = new Color(image.getRGB(j, i));
+               int red = (int)(c.getRed() * 0.299);
+               int green = (int)(c.getGreen() * 0.587);
+               int blue = (int)(c.getBlue() *0.114);
+               Color newColor = new Color(red+green+blue,red+green+blue,red+green+blue);
+               
+               image.setRGB(j,i,newColor.getRGB());
+            }
+         }
+         
+         File ouptut = new File("grayscale.jpg");
+         ImageIO.write(image, "jpg", ouptut);
+         
+      } catch (Exception e) {}
+   }
+   
+   static public void main(String args[]) throws Exception 
+   {
+      GrayScale obj = new GrayScale();
+   }
+}
\ No newline at end of file
diff --git a/Conversion_CYC/blackandwhite.jpg b/Conversion_CYC/blackandwhite.jpg
new file mode 100644 (file)
index 0000000..e7829c9
Binary files /dev/null and b/Conversion_CYC/blackandwhite.jpg differ
diff --git a/Conversion_CYC/grayscale.jpg b/Conversion_CYC/grayscale.jpg
new file mode 100644 (file)
index 0000000..cfde1c2
Binary files /dev/null and b/Conversion_CYC/grayscale.jpg differ
diff --git a/Conversion_CYC/test.jpg b/Conversion_CYC/test.jpg
new file mode 100644 (file)
index 0000000..be810ad
Binary files /dev/null and b/Conversion_CYC/test.jpg differ