Compare commits

...

2 Commits

Author SHA1 Message Date
gulerdav 92ee656a5d Merge pull request #75 from schrom01/fix_imageLoad_M3
fixed image loading when app is packed as jar
2022-12-05 10:59:41 +01:00
Elias Csomor c64339c945 fixed image loading when app is packed as jar
https://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream
2022-12-02 12:04:51 +01:00
1 changed files with 3 additions and 7 deletions

View File

@ -21,13 +21,9 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
@Override
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
Image result = null;
URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
if (imageUrl != null) {
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
result = new Image(is);
} catch (IllegalArgumentException | URISyntaxException e) {
throw new IOException(String.format("Cannot find Image \"%s\"\n", imageUrl.getFile()));
}
InputStream is = PlantList.class.getResourceAsStream(String.format("images/%s", parser.getText()));
if (is != null) {
result = new Image(is);
}
return result;
}