UPDATE
剛剛發佈的固定代碼,所以如果別人有困難時,他們可以看看:
public class Inderxer {
public void indexFolder(Path path) throws IOException {
List<Image> images = new LinkedList<>();
Files.walk(path).parallel().forEach(E -> {
if (!E.toFile().isDirectory() && !E.toFile().getName().contains(".DS") && FilenameUtils.getExtension(E.toFile().toString()) != ".kmz") {
try {
Metadata metadata = ImageMetadataReader.readMetadata(E.toFile());
if (FilenameUtils.getExtension(E.toFile().toString()).contains("jpg")) {
List<Directory> dirs = metadata.getDirectoriesOfType(JpegDirectory.class).stream().collect(Collectors.toList());
images.add(new Image(E.getFileName().toString(), FilenameUtils.getExtension(E.toFile().toString()), dirs));
} else {
List<Directory> dirs = metadata.getDirectoriesOfType(PngDirectory.class).stream().collect(Collectors.toList());
images.add(new Image(E.getFileName().toString(), FilenameUtils.getExtension(E.toFile().toString()), dirs));
}
} catch (ImageProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
images.stream()
.forEach(M -> M.getDirectory().stream()
.forEach(D -> {
if (!M.getType().equals("png")) {
M.setSize(createDimentionArray(D.getDescription(1), D.getDescription(3), "jpg"));
} else {
M.setSize(createDimentionArray(D.getDescription(1), D.getDescription(2), "png"));
}
}));
images.forEach(System.out::println);
}
private String createDimentionArray(String h, String w, String type) {
String res = "";
if (type.equals("jpg")) {
if (h != null && w != null) {
String[] hsplit = h.split("pixels");
String[] wsplit = w.split("pixels");
if (hsplit[0] != null && wsplit[0] != null) {
res = hsplit[0]; //Hight
res += wsplit[0]; //Width
res += "\n";
}
return res;
} else {
return null;
}
} else {
if (h != null && w != null) {
String[] hsplit = h.split("pixels");
String[] wsplit = w.split("pixels");
if (hsplit[0] != null && wsplit[0] != null) {
res = hsplit[0]; //Hight
res += " ";
res += wsplit[0]; //Width
res += "\n";
}
return res;
} else {
return null;
}
}
}
}
這應該是工作,你打電話'setSize'內'E'的範圍。 –
然後,它必須是我的代碼的其他部分返回空值.. – Lasse
您可以添加'.peek(System.out :: println)'調用到您的流打印出流中正在處理的值.. 。 –