1 | /** This class is not currently used and therefore will not be compiled by makegli. */
|
---|
2 |
|
---|
3 | package org.greenstone.gatherer.feedback;
|
---|
4 |
|
---|
5 | import java.io.*;
|
---|
6 | import javax.imageio.*;
|
---|
7 | import java.awt.*;
|
---|
8 | import java.awt.image.*;
|
---|
9 | import com.sun.image.codec.jpeg.*;
|
---|
10 | import javax.swing.*;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * This class will separate a image file into 2 jpeg image files by taking
|
---|
14 | * all the point in that image file that has the color red and save all that
|
---|
15 | * points to another image file, while all the other point to another image
|
---|
16 | * file.
|
---|
17 | * @author Veronica Liesaputra
|
---|
18 | */
|
---|
19 | public class SeparateGraphs
|
---|
20 | {
|
---|
21 | /**
|
---|
22 | * This is the BufferedImage that we want to separate.
|
---|
23 | */
|
---|
24 | private BufferedImage bi;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * This constructor will save the image inside the file with the specified
|
---|
28 | * filename to the BufferedImage.
|
---|
29 | */
|
---|
30 | public SeparateGraphs(String filename)
|
---|
31 | {
|
---|
32 | try
|
---|
33 | {
|
---|
34 | File f = new File(filename);
|
---|
35 | bi = ImageIO.read(f);
|
---|
36 | }
|
---|
37 | catch(IOException exp) {}
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * This method will separate bi into 2 image and save it to
|
---|
42 | * jpeg files with the specified filename.
|
---|
43 | * The 2 image separated will be, 1 image is the image of all the points in bi that
|
---|
44 | * have the color red and another image is the image of all other points in bi that
|
---|
45 | * do not have the color red.
|
---|
46 | * @param file1 this is the filename for the image of all other points that do not have color red.
|
---|
47 | * @param file2 this is the filename for the image of all points that have the color red.
|
---|
48 | */
|
---|
49 | public void separate(String file1,String file2)
|
---|
50 | {
|
---|
51 | BufferedImage bi1,bi2;
|
---|
52 |
|
---|
53 | int width = bi.getWidth();
|
---|
54 | int height = bi.getHeight();
|
---|
55 |
|
---|
56 | bi1 = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
|
---|
57 | bi2 = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
|
---|
58 |
|
---|
59 | for (int y = 0 ; y < height ; y++)
|
---|
60 | {
|
---|
61 | for (int x = 0 ; x < width ; x++)
|
---|
62 | {
|
---|
63 | int rgb = bi.getRGB(x,y);
|
---|
64 | Color c = new Color(rgb,true);
|
---|
65 | if (c != Color.RED)
|
---|
66 | {
|
---|
67 | bi1.setRGB(x,y,rgb);
|
---|
68 | }
|
---|
69 | else
|
---|
70 | {
|
---|
71 | bi2.setRGB(x,y,rgb);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | save(bi1,file1);
|
---|
77 | save(bi2,file2);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * This method will save the BufferedImage into a jpeg file with the specified filenames.
|
---|
82 | * @param b is the BufferedImage to be saved.
|
---|
83 | * @param filename is the name of the jpeg files.
|
---|
84 | */
|
---|
85 | public void save(BufferedImage b,String filename)
|
---|
86 | {
|
---|
87 | try
|
---|
88 | {
|
---|
89 | File file = new File(filename);
|
---|
90 | FileOutputStream out = new FileOutputStream(file);
|
---|
91 |
|
---|
92 | JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
|
---|
93 | JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(b);
|
---|
94 | param.setQuality(1.0f, false);
|
---|
95 | encoder.setJPEGEncodeParam(param);
|
---|
96 | encoder.encode(b);
|
---|
97 |
|
---|
98 | } catch (Exception ex) {}
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|