source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/feedback/Separating.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: 2.9 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 * This method will separate 1 image file into 2 image with the help of
14 * another file and sace the difference into a jpeg files.
15 * For example : We have 1 image file which is a screen shot and another image file
16 * is the screenshot with some line in it.
17 * This class will separate the screen shot and the line into 2 separates
18 * images.And then it will save the line into a jpeg files.
19 *
20 * @author Veronica Liesaputra
21 */
22public class Separating
23{
24 /**
25 * This is the BufferedImage of image inside the reference image file.
26 */
27 private BufferedImage bi;
28 /**
29 * This is the BufferedImage of image that we want to separate into
30 * 2 different image using the reference file.
31 */
32 private BufferedImage src_bi;
33
34 /**
35 * It will read whats inside the 2 given filenames and put it in the
36 * right BufferedImage.
37 * @param filename1 this is the file name of the reference image file.
38 * @param filename2 this is the file name of the file we want to separate into 2.
39 */
40 public Separating(String filename1,String filename2)
41 {
42 try
43 {
44 File f1 = new File(filename1);
45 File f2 = new File(filename2);
46 bi = ImageIO.read(f1);
47 src_bi = ImageIO.read(f2);
48 }
49 catch(IOException exp) {}
50 }
51
52 /**
53 * This method will get the difference that exist between bi and src_bi and
54 * will save the difference inside a jpeg file with the specified file name.
55 * @param file1 is the name of the file where we want to save the image.
56 */
57 public void separate(String file1)
58 {
59 BufferedImage bi1;
60
61 int width = bi.getWidth();
62 int height = bi.getHeight();
63
64 bi1 = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
65
66 for (int y = 0 ; y < height ; y++)
67 {
68 for (int x = 0 ; x < width ; x++)
69 {
70 int rgb = bi.getRGB(x,y);
71 int src_rgb = src_bi.getRGB(x,y);
72
73 if (src_rgb != rgb)
74 {
75 bi1.setRGB(x,y,rgb);
76 }
77 }
78 }
79
80 save(bi1,file1);
81 }
82
83 /**
84 * This method will save a BufferedImage to a jpeg file with the specified filename.
85 * @param b is the BufferedImage to be saved.
86 * @param filename is the name of the jpeg file.
87 */
88 public void save(BufferedImage b,String filename)
89 {
90 try
91 {
92 File file = new File(filename);
93 FileOutputStream out = new FileOutputStream(file);
94
95 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
96 JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(b);
97 param.setQuality(1.0f, false);
98 encoder.setJPEGEncodeParam(param);
99 encoder.encode(b);
100
101 } catch (Exception ex) {}
102 }
103}
104
105
106
107
108
Note: See TracBrowser for help on using the repository browser.