I have a number of images that are displayed in my application. They are generated by the data I enter. Now I want to save the images in one png file (would prefer jpg but png is also doing the job). Right now the last image will be overwritten by the next image, so that only the last image in stored in the png file. I thought about creating one image that consists of all the images I want to save in the png file. Does anyone have an idea of how to do that? Or is there a simpler way of how to save the images in one file?
private final ObservableList<Image> pdfFilePages = FXCollections.observableArrayList();
pngButton.setOnAction(e -> {
if (pdfFilePages.size() > 0) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(I18N.get("key.save_to_png"));
File file = fileChooser.showSaveDialog(dialogStage);
if (file != null) {
for (Image img : pdfFilePages) {
ImageView imgView = new ImageView(img);
try {
BufferedImage bi = SwingFXUtils.fromFXImage(img, null);
ImageIO.write(bi, "png", file);
} catch (IOException e1) {
LOGGER.error(e1.getMessage(), e1);
}
}
}
}
});