From 0a1982b66a61f68b38bec0f808366d8ae6d27d13 Mon Sep 17 00:00:00 2001 From: TheDarkDesync <82680013+TheDarkDesync@users.noreply.github.com> Date: Tue, 18 Jan 2022 19:51:48 +0100 Subject: [PATCH] [feat] save generated images to temp (#39) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat] getter in TrialData * [fix] datetime * [fix] startTime can be null * [feat] AbsScene und Log hinzugefügt * [fix] stage * [fix] resourcs directory name * [fix] controller name * [fix] log size * [feat] Image Saver for generated Images * [style] checkstyle Co-authored-by: joshuajeschek Co-authored-by: Joshua Jeschek <64850647+joshuajeschek@users.noreply.github.com> --- .../java/github/weichware10/util/Files.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/github/weichware10/util/Files.java b/src/main/java/github/weichware10/util/Files.java index 997df26..2d1a097 100644 --- a/src/main/java/github/weichware10/util/Files.java +++ b/src/main/java/github/weichware10/util/Files.java @@ -1,5 +1,7 @@ package github.weichware10.util; +import java.awt.image.BufferedImage; +import java.awt.image.RenderedImage; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -10,6 +12,7 @@ import java.net.URL; import java.util.Arrays; import java.util.List; +import javax.imageio.ImageIO; import org.apache.commons.io.FileUtils; /** @@ -78,6 +81,29 @@ public static String saveImage(String imageUrl) throws MalformedURLException, return destName; } + /** + * Speichert genertiertes Bild im temp Ordner. + * + * @param buffImage - Generiertes Bild + * @param fileName - Dateiname + * @return Speicheradresse + * @throws IOException + * @throws IllegalArgumentException + */ + public static String saveGeneratedImage(BufferedImage buffImage, String fileName) + throws IOException, IllegalArgumentException { + if (tmpdir == null) { + tmpdir = createTempDir(); + } + RenderedImage rendImage = buffImage; + + String destName = tmpdir + "/" + fileName; + File file = new File(destName); + ImageIO.write(rendImage, "png", file); + + return destName; + } + /** * Löscht angelegten temporären Ordner beim Beenden der App. */