소스 검색

now on page 23 of script

Noah Vogt 3 년 전
부모
커밋
f1785bc5ec

+ 61 - 0
image-project/GraustufenImage.java

@@ -0,0 +1,61 @@
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import javax.imageio.ImageIO;
+
+public class GraustufenImage {
+
+    public static void main(String [] args) {
+
+        String outFormat = "png";
+        File inputPath = new File("img/Taj_Mahal4.png");
+        File outputPath = new File("img/Taj_Mahal4_grau.png");
+
+        BufferedImage original_image = null;
+
+        try {
+            original_image = ImageIO.read(inputPath);
+            System.out.println("Reading " + inputPath + " complete !"); }
+        catch (IOException e) {
+            System.out.println("Error: " + e);
+        }
+
+        int width =  original_image.getWidth();
+        int height =  original_image.getHeight();
+
+        System.out.println("\n" + "width = " + width + " height = " +
+                           height + "\n");
+
+        BufferedImage newImage = new BufferedImage(width, height,
+                                         BufferedImage.TYPE_INT_ARGB); 
+        newImage.createGraphics().drawImage(original_image, 0, 0, null);
+
+    
+        int p, new_p, a, r, g, b;
+
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                p = original_image.getRGB(x, y);
+
+                a = (p >> 24) & 0xFF; r = (p >> 16) & 0xFF;
+                g = (p >> 8) & 0xFF; b = p & 0xFF;
+
+                int average = (r + g + b)/3;
+                new_p = (a << 24) | (average << 16) | (average << 8) | average;
+
+                newImage.setRGB(x, y, new_p);
+            }
+        }
+
+        try {
+            ImageIO.write(newImage, outFormat, outputPath);
+            System.out.println("Writing " + outputPath + " complete !"); }
+        catch(IOException e) {
+            System.out.println("Error: " + e); 
+            System.exit(1);
+        }
+
+        System.exit(0);
+    }
+}

+ 2 - 2
image-project/MyImageInfo.java

@@ -6,8 +6,8 @@ import javax.imageio.ImageIO;
 public class MyImageInfo{
     public static void main(String args[]) throws IOException{
         BufferedImage image_on_disk = null;
-        File inputFilePath = new File("img/wojak-wage-cage-comfy-pepe.png"),
-            outputFilePath = new File("img/wojak-wage-cage-comfy-pepe.jpg");
+        File inputFilePath = new File("img/Sample_204_255_20_147.png"),
+            outputFilePath = new File("img/Sample_204_255_20_147.jpg");
 
         ImageInfo imageInfo = new ImageInfo(inputFilePath);
         System.out.println("Informationen zum input-File " + inputFilePath +

+ 21 - 3
image-project/MyImage_ohne_A_mit_A.java

@@ -16,7 +16,7 @@ public class MyImage_ohne_A_mit_A {
                outFormat = "";
 
         FileNameSelector fc = new FileNameSelector("img/");
-        //         fc.setPath("img/");
+                 fc.setPath("img/Sample_204_255_20_147.png");
 
         File fin = null, fout = null;            
 
@@ -26,9 +26,10 @@ public class MyImage_ohne_A_mit_A {
             inFileNamePfad = "img/" + inFileName;
             //             System.out.println("inFileNamePfad = " + inFileNamePfad);
 
-            fin = new File(inFileNamePfad); // input file path
+            fin = new File("img/Sample_204_255_20_147.png"); // input file path
 
-            String [] inFileName_Teil = inFileName.split(Pattern.quote(".")); // Ermitteln den Stamm- und die Erweiterung-Teile von inFileName:
+            String [] inFileName_Teil = inFileName.split(Pattern.quote(".")); 
+            // Ermitteln den Stamm- und die Erweiterung-Teile von inFileName:
             // inFileName_Teil[0] = Stammname, inFileName_Teil[1] = Erweiterung (png, jpg, ...)
 
             outFileName = Db.readLine("Geben Sie den Namen des Output-Files" + 
@@ -87,6 +88,22 @@ public class MyImage_ohne_A_mit_A {
         int width =  image_on_disk.getWidth();
         int height =  image_on_disk.getHeight();
 
+        int zahlenwert = image_on_disk.getRGB(0,0);
+        System.out.println("\nZAHLENWERT (0,0): \n" + zahlenwert);
+        int a = (zahlenwert >> 24) & 0xFF;
+        int r = (zahlenwert >> 16) & 0xFF;
+        int g = (zahlenwert >> 8) & 0xFF;
+        int b = zahlenwert & 0xFF;
+        System.out.println("a = " + a + " = " + Integer.toString(a, 2) + 
+                           "\nr = " + r + " = " + Integer.toString(r, 2) + 
+                           "\ng = " + g + " = " + Integer.toString(g, 2) + 
+                           "\nb = " + b + " = " + Integer.toString(b, 2));
+
+        int new_a = 255, new_r = 100, new_g = 150, new_b = 200, new_p = 0;
+
+        new_p = (new_a << 24) | (new_r << 16) | (new_g << 8) | new_b;
+
+
         System.out.println("\n" + "width = " + width + " height = " + height + "\n");
 
         if (image_on_disk.getColorModel().hasAlpha()) {
@@ -124,6 +141,7 @@ public class MyImage_ohne_A_mit_A {
         //******************** Image schreiben ************************
 
         try {
+            image_memory.setRGB(0, 0, new_p);
             ImageIO.write(image_memory, outFormat, fout);
             System.out.println("Writing " + fout + " complete !"); }
         catch(IOException e) {

BIN
image-project/img/Sample_255_100_150_200.png


BIN
image-project/img/Taj_Mahal4_grau.png