Moved bit input and output streams into Svjatoslav Commons library.
[imagesqueeze.git] / src / main / java / eu / svjatoslav / imagesqueeze / sampleApplication / Main.java
1 /*
2  * Imagesqueeze - Image codec optimized for photos.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.imagesqueeze.sampleApplication;
11
12 import java.io.File;
13 import java.io.IOException;
14 import java.io.InputStream;
15
16 public class Main {
17
18         public static void main(final String[] args) {
19
20                 try {
21
22                         final String image = "colorful photo";
23                         final String sourceDirectory = "/eu/svjatoslav/imagesqueeze/sampleApplication/data/";
24
25                         // create visible frame
26                         // load image into frame
27                         final InputStream inputStream = Main.class
28                                         .getResourceAsStream(sourceDirectory + image + ".png");
29
30                         final ImageFrame frame = new ImageFrame("Original image");
31                         frame.getImagePanel().loadImage(inputStream, false);
32                         frame.setVisible(true);
33
34                         // encode image into file
35                         frame.getImagePanel().saveImage(new File(image + ".ImgSqz"));
36
37                         // create second frame for decoded image
38                         final ImageFrame frame2 = new ImageFrame("Encoded -> Decoded");
39
40                         // decode image
41                         frame2.getImagePanel().loadImage(new File(image + ".ImgSqz"), true);
42                         frame2.setVisible(true);
43
44                 } catch (final IOException exception) {
45                         System.out.println("Error while loading an image: " + exception);
46                 }
47
48         }
49
50 }