Wie kann ich in einem dir alle Bilder einlesen, Java?
Hier mein Code:
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Read extends Component {
public static void main(String[] foo) {
new Read();
}
public void printPixelARGB(int pixel, int i, int j) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel) & 0xff;
System.out.println("argb: " + alpha + ", " + red + ", " + green + ", " + blue);
int x = ((alpha-(765-red-green-blue)/3)<<24) + (red<<16) + (green<<8) + blue;
double y = x < 0 ? (1.0/(x))/-1 : x > 0 ? 1.0/x : 0;
System.out.println(y);
}
private void marchThroughImage(BufferedImage image) {
int w = image.getWidth();
int h = image.getHeight();
System.out.println("width, height: " + w + ", " + h);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
System.out.println("x,y: " + j + ", " + i);
int pixel = image.getRGB(j, i);
printPixelARGB(pixel, i, j);
System.out.println("");
}
}
}
public Read() {
try {
// get the BufferedImage, using the ImageIO class
BufferedImage image =
ImageIO.read(this.getClass().getResource("3.png"));
marchThroughImage(image);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
}
Meine Frage... Bei der Zeile mit "3.png" soll stehen, dass alle png Files einer dir z.b. C:\Users\xy\pngdir eingelesen werden... Wie macht man das?
LG