|
15 | 15 | public class DrawableScreenshot { |
16 | 16 |
|
17 | 17 | private final DrawingConfiguration drawingConfiguration; |
| 18 | + private final Vector extend; |
18 | 19 | private TransformedGraphics graphics; |
19 | 20 | private File screenshotName; |
20 | 21 | private File drawingsOutput; |
21 | 22 | private BufferedImage drawings; |
22 | | - private final Vector extend; |
23 | 23 |
|
24 | 24 | public DrawableScreenshot(Vector extend, SimpleTransform transform, DrawingConfiguration drawingConfiguration, String rootElementReadableName, File screenshotName) { |
25 | 25 | this.drawingConfiguration = drawingConfiguration; |
26 | 26 | this.screenshotName = screenshotName; |
| 27 | + File imgFolder = new File(TARGET_AUTOMOTION_IMG); |
| 28 | + if (!imgFolder.exists()) { |
| 29 | + imgFolder.mkdir(); |
| 30 | + } |
27 | 31 | drawingsOutput = new File(TARGET_AUTOMOTION_IMG + rootElementReadableName.replaceAll("[\\W]|_", "") + "-draw-" + System.currentTimeMillis() + Helper.getGeneratedStringWithLength(7) + ".png"); |
28 | 32 |
|
29 | 33 | try { |
30 | 34 | this.extend = extend; |
31 | | - drawings = new BufferedImage(extend.getX().intValue(), extend.getY().intValue(), |
32 | | - BufferedImage.TYPE_INT_ARGB); |
| 35 | + drawings = new BufferedImage(extend.getX().intValue(), extend.getY().intValue(), BufferedImage.TYPE_INT_ARGB); |
33 | 36 |
|
34 | 37 | Graphics2D g2d = drawings.createGraphics(); |
35 | 38 |
|
@@ -66,10 +69,14 @@ public void drawHorizontalLine(Scalar y) { |
66 | 69 |
|
67 | 70 | public void saveDrawing() { |
68 | 71 | try { |
69 | | - ImageIO.write(drawings, "png", drawingsOutput); |
70 | | - } catch (IOException | NullPointerException e) {} |
| 72 | + if (drawings != null && drawingsOutput != null) { |
| 73 | + ImageIO.write(drawings, "png", drawingsOutput); |
| 74 | + } |
| 75 | + } catch (NullPointerException | IOException ignored) {} |
71 | 76 |
|
72 | | - drawings.getGraphics().dispose(); |
| 77 | + if (drawings != null) { |
| 78 | + drawings.getGraphics().dispose(); |
| 79 | + } |
73 | 80 | } |
74 | 81 |
|
75 | 82 | public void drawRoot(UIElement rootElement) { |
|
0 commit comments