source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/feedback/CombineGraphs.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 4.0 KB
Line 
1/** This class is not currently used and therefore will not be compiled by makegli. */
2
3package org.greenstone.gatherer.feedback;
4
5import java.io.*;
6import javax.imageio.*;
7import java.awt.*;
8import java.awt.image.*;
9import com.sun.image.codec.jpeg.*;
10import javax.swing.*;
11
12/**
13 * CombineGraphs class is a class to combine 2 images file into 1 jpeg file
14 * called test.jpg using point by point comparison.
15 * <p>User need to supplied the valid exist filenames of the 2 images that
16 * they want to combine.If in any one point in 2nd image file is not transparent
17 * then that point will be drawn to the 1st image file.</p>
18 * <p>To run this class properly the format is :
19 * <br><i>java CombineGraphs filename1 filename2</i>
20 * <br>where filename1 is the names of the first image file.
21 * <br>and filename2 is the names of the second image file. This file must
22 * contains transparent.</p>
23 * <p>For example: If user wants to combine the screenshot image file with the
24 * image file of the scribble lines, then
25 * <br>filename1 will be the filename of the screenshot image file, and
26 * <br>filename2 will be the filename of the scribble lines image file.</p>
27 *
28 * @author Veronica Liesaputra
29 */
30
31public class CombineGraphs extends JPanel
32{
33 /**
34 * This is a variable to stored the image that is stored inside f1.
35 * After the combine method called this variable will store the resulted image of
36 * combining 2 images together.
37 */
38 private BufferedImage bi1;
39
40 /**
41 * This is a variable to stored the image that is stored inside f2.
42 */
43 private BufferedImage bi2;
44
45 /**
46 * This is a variable to stored the first image file that the user supplied.
47 */
48 private File f1;
49
50 /**
51 * This is a variable to stored the second image file that the user supplied.
52 */
53 private File f2;
54
55 /**
56 * It will read the image files user supplied and stored the image
57 * to the appropriate bufferedimage variable.
58 * (Precondition: (file1 != null) && (file2 != null))
59 * @param file1 the name of the first image file.
60 * @param file2 the name of the second image file.
61 */
62 public CombineGraphs(String file1,String file2)
63 {
64 try
65 {
66 f1 = new File(file1);
67 f2 = new File(file2);
68 bi1 = ImageIO.read(f1);
69 bi2 = ImageIO.read(f2);
70 }
71 catch(IOException exp) {}
72 }
73
74 /**
75 * This method will combine the 2 buffered images into 1 buffered image and
76 * saved it to an output file in jpeg format.
77 * (Precondition: (filename != null))
78 * @param filename the name of the output file.
79 * (Postcondition: the combined image is stored in a jpeg file with the name
80 * as specified in filename.)
81 */
82 public void combine(String filename)
83 {
84
85 /*using bi1 as the base layer that we use to compare point by point with bi2.
86 if in one point in bi2 its not transparent then we draw that point to bi1.*/
87 Graphics2D G1;
88
89 G1 = bi1.createGraphics();
90
91 int width = bi2.getWidth();
92 int height = bi2.getHeight();
93
94 for (int y = 0 ; y < height ; y++)
95 {
96 for (int x = 0 ; x < width ; x++)
97 {
98 int rgb = bi2.getRGB(x,y);
99 if (rgb != 0)
100 {
101 G1.setColor(new Color(rgb,true));
102 G1.drawLine(x,y,x,y);
103 }
104 }
105 }
106
107 // Save the combined bufferedimage into a jpeg output file.
108 try {
109 File file = new File(filename);
110 FileOutputStream out = new FileOutputStream(file);
111
112 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
113 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi1);
114 param.setQuality(1.0f, false);
115 encoder.setJPEGEncodeParam(param);
116 encoder.encode(bi1);
117
118 } catch (Exception ex) {}
119 }
120
121 /**
122 * This the main method that need 2 inputs from the user for it to
123 * work properly.
124 * The inputs are the 2 image filenames that user want to combine.
125 */
126 public static void main (String[] args)
127 {
128 CombineGraphs cb = new CombineGraphs(args[0],args[1]);
129 cb.combine("test.jpg");
130 }
131}
132
133
134
135
136
137
138
Note: See TracBrowser for help on using the repository browser.