@@ -20,22 +20,22 @@ public class ImageComparisonTools {
20
20
* @param image resulting image.
21
21
*/
22
22
public static Frame createGUI (BufferedImage image ) {
23
- JFrame frame = new JFrame ("The result of the comparison" );
23
+ JFrame frame = new JFrame ("The result of the comparison" );
24
24
frame .setDefaultCloseOperation ( WindowConstants .EXIT_ON_CLOSE );
25
25
JLabel label = new JLabel ();
26
- label .setIcon (new ImageIcon (image , "Result" ));
26
+ label .setIcon ( new ImageIcon ( image , "Result" ) );
27
27
frame .getContentPane ().add (label , BorderLayout .CENTER );
28
- frame .setPreferredSize (new Dimension ( ( image .getWidth () ), image .getHeight () ) );
28
+ frame .setPreferredSize (new Dimension ( image .getWidth (), ( int )( image .getHeight () * 1.1 ) ) );
29
29
frame .pack ();
30
- frame .setLocationRelativeTo (null );
31
- frame .setVisible (true );
30
+ frame .setLocationRelativeTo ( null );
31
+ frame .setVisible ( true );
32
32
return frame ;
33
33
}
34
34
35
- static BufferedImage deepCopy ( BufferedImage iamge ) {
36
- ColorModel cm = iamge .getColorModel ();
35
+ static BufferedImage deepCopy ( BufferedImage image ) {
36
+ ColorModel cm = image .getColorModel ();
37
37
boolean isAlphaPremultiplied = cm .isAlphaPremultiplied ();
38
- WritableRaster raster = iamge .copyData (null );
38
+ WritableRaster raster = image .copyData (null );
39
39
return new BufferedImage (cm , raster , isAlphaPremultiplied , null );
40
40
}
41
41
@@ -85,4 +85,16 @@ public static boolean isDifferent( int x, int y, BufferedImage image1, BufferedI
85
85
public static BufferedImage readImageFromResources ( String path ) throws IOException , URISyntaxException {
86
86
return ImageIO .read ( new File ( ImageComparison .class .getClassLoader ().getResource ( path ).toURI ().getPath () ) );
87
87
}
88
+
89
+ /**
90
+ * Save image to the provided path.
91
+ * @param path the path to the saving image.
92
+ * @param image the {@code BufferedImage} object of this specific image.
93
+ * @throws IOException
94
+ */
95
+ public static void saveImage (String path , BufferedImage image ) throws IOException {
96
+ // make dir if it's not using from Gradle.
97
+ new File ( path ).mkdirs ();
98
+ ImageIO .write ( image , "png" , new File ( path ) );
99
+ }
88
100
}
0 commit comments