Schupp icon

JavaApplication8

Schupp | PRO | 12/09/18 03:00:01 PM UTC | 0 ⭐ | 462 👁️ | Never ⏰ | []
Java |

2.12 KB

|

None

|

0 👍

/

0 👎

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication8;
 
import java.io.*;
import java.awt.image.*;
import static java.lang.System.arraycopy;
import java.util.*;
import javax.imageio.*;
 
class JavaApplication8 {
 
    static int pointer = 0;
 
    public static void main(String... args) throws IOException {
        String extension = "";
        try (FileOutputStream fos = new FileOutputStream("test.bin")) {
            File file;
            File[] files = new File("./").listFiles();
 
            for (File filec : files) {
                if (filec.isDirectory()) {
                    System.out.println("Directory: " + filec.getName());
 
                } else {
                    System.out.println("File: " + filec.getName());
                    int i = filec.getName().lastIndexOf('.');
                    if (i > 0) {
                        extension = filec.getName().substring(i + 1);
                    }
                    System.out.printf(extension);
                    if (extension.equals("BMP") || extension.equals("bmp")) {
 
                        file = new File(filec.getName());
                        BufferedImage bimage = ImageIO.read(file);
                        int[] line = new int[bimage.getWidth()];
                        for (int x = 0; x < bimage.getHeight(); x++) {
 
                            //System.out.printf("%d ", x);
                            bimage.getRGB(0, x, bimage.getWidth(), 1, line, 0, 0);
                            for (int y = 0; y < bimage.getWidth(); y++) {
                                fos.write((byte) line[y]);
                            }
                        }//}
 
                        System.out.printf("loaded %dx%d pixel image%n",
                                bimage.getWidth(),
                                bimage.getHeight());
                    }
                }
                extension = "";
            }
            fos.close();
        }
 
    }
 
}

Comments