Schupp

JavaApplication8

Dec 9th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication8;
  7.  
  8. import java.io.*;
  9. import java.awt.image.*;
  10. import static java.lang.System.arraycopy;
  11. import java.util.*;
  12. import javax.imageio.*;
  13.  
  14. class JavaApplication8 {
  15.  
  16.     static int pointer = 0;
  17.  
  18.     public static void main(String... args) throws IOException {
  19.         String extension = "";
  20.         try (FileOutputStream fos = new FileOutputStream("test.bin")) {
  21.             File file;
  22.             File[] files = new File("./").listFiles();
  23.  
  24.             for (File filec : files) {
  25.                 if (filec.isDirectory()) {
  26.                     System.out.println("Directory: " + filec.getName());
  27.  
  28.                 } else {
  29.                     System.out.println("File: " + filec.getName());
  30.                     int i = filec.getName().lastIndexOf('.');
  31.                     if (i > 0) {
  32.                         extension = filec.getName().substring(i + 1);
  33.                     }
  34.                     System.out.printf(extension);
  35.                     if (extension.equals("BMP") || extension.equals("bmp")) {
  36.  
  37.                         file = new File(filec.getName());
  38.                         BufferedImage bimage = ImageIO.read(file);
  39.                         int[] line = new int[bimage.getWidth()];
  40.                         for (int x = 0; x < bimage.getHeight(); x++) {
  41.  
  42.                             //System.out.printf("%d ", x);
  43.                             bimage.getRGB(0, x, bimage.getWidth(), 1, line, 0, 0);
  44.                             for (int y = 0; y < bimage.getWidth(); y++) {
  45.                                 fos.write((byte) line[y]);
  46.                             }
  47.                         }//}
  48.  
  49.                         System.out.printf("loaded %dx%d pixel image%n",
  50.                                 bimage.getWidth(),
  51.                                 bimage.getHeight());
  52.                     }
  53.                 }
  54.                 extension = "";
  55.             }
  56.             fos.close();
  57.         }
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment