Skip to content

Commit

Permalink
[feat] save generated images to temp (#39)
Browse files Browse the repository at this point in the history
* [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 <joshua.jeschek@gmail.com>
Co-authored-by: Joshua Jeschek <64850647+joshuajeschek@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 18, 2022
1 parent bb19a52 commit 0a1982b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/github/weichware10/util/Files.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 0a1982b

Please sign in to comment.