-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixelReader.java
More file actions
106 lines (95 loc) · 3.63 KB
/
PixelReader.java
File metadata and controls
106 lines (95 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
public class PixelReader {
private Robot robot;
private Rectangle rectangle;
private Dimension dimension;
private BufferedImage bufferedImage;
ArrayList<String> colorList;
public PixelReader(){
try {
robot = new Robot();
} catch (AWTException ex) {
Logger.getLogger(PixelReader.class.getName()).log(Level.SEVERE, null, ex);
}
dimension= Toolkit.getDefaultToolkit().getScreenSize();
rectangle = new Rectangle(dimension);
bufferedImage=robot.createScreenCapture(rectangle);
}
public void refreshScreen()
{
bufferedImage = robot.createScreenCapture(rectangle);
}
public void readVertically(int x, int y, int width, FileSaver f){
if(x < dimension.width && y <dimension.height && (x+width) < dimension.width){
refreshScreen();
colorList = new ArrayList<String>();
for(int i = x; i < (x+width); i++){
robot.mouseMove(i, y);
robot.delay(5);
System.out.println(bufferedImage.getRGB(i, y));
colorList.add(String.valueOf(bufferedImage.getRGB(i, y)));
}
f.writeToFile(colorList.toArray(new String[colorList.size()]));
}
else
{
System.out.println("Your size is not that big, it's accually "
+ dimension.width+"x"+dimension.height+"...");
}
}
public void readHorizontally(int x, int y, int height, FileSaver f){
if(x < dimension.width && y <dimension.height && (y+height) < dimension.height){
refreshScreen();
colorList = new ArrayList<String>();
for(int i = y; i < (y+height); i++){
robot.mouseMove(x, i);
robot.delay(5);
System.out.println(bufferedImage.getRGB(x, i));
colorList.add(String.valueOf(bufferedImage.getRGB(x, i)));
}
f.writeToFile(colorList.toArray(new String[colorList.size()]));
}
else
{
System.out.println("Your size is not that big, it's accually "
+ dimension.width+"x"+dimension.height+"...");
}
}
public void readDiagonally(int x, int y, int diag, FileSaver f){
if(x < dimension.width && y <dimension.height && (x+diag) < dimension.width && y+diag < dimension.height){
refreshScreen();
for(int i = x, j=y; i < (x+diag); i++, j++){
robot.mouseMove(i, j);
robot.delay(5);
System.out.println(bufferedImage.getRGB(i, j));
colorList.add(String.valueOf(bufferedImage.getRGB(i, j)));
}
f.writeToFile(colorList.toArray(new String[colorList.size()]));
}
else
{
System.out.println("Your size is not that big, it's accually "
+ dimension.width+"x"+dimension.height+"...");
}
}
// public void findColor(int kolor){
// refreshScreen();
// for(int x=1;x<dimension.width;x++)
// {
// for(int y = 1; y<dimension.height;y++)
// {
// if(bufferedImage.getRGB(x,y)==kolor)
// {
// robot.mouseMove(x, y);
// System.out.println("Here!!!");
// return;
// }
// }
// }
// System.out.println("No such color on you screen...");
// }
}