- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
public static void createShotAndSend() {
Toolkit tool = Toolkit.getDefaultToolkit();
Dimension screen = tool.getScreenSize();
int w = screen.width;
int h = screen.height;
int x = MouseInfo.getPointerInfo().getLocation().x-W/2;
int y = MouseInfo.getPointerInfo().getLocation().y-H/2;
if(x == ox && y == oy) {
return;
}
ox = x;
oy = y;
int sx = Math.min(Math.max(x, 0), w-W);
int sy = Math.min(Math.max(y, 0), h-H);
BufferedImage capture;
try {
capture = (new Robot()).createScreenCapture(new Rectangle(sx, sy, W, H));
} catch (AWTException ex) {
System.err.println("Failed screen capturing!");
return;
}
ByteArrayOutputStream data = new ByteArrayOutputStream();
try {
ImageIO.write(capture, "JPG", data);
} catch (IOException ex) {
System.err.println("Failed writing capture!");
return;
}
byte[] toSend = data.toByteArray();
int l = data.size();
byte[] size = itob(l);
//pool - Client[]
for(int i = 0; i < pool.length; i++) {
if(pool[i] == null) continue;
if(!pool[i].isActive()) continue;
pool[i].send(size, 0, 4);
pool[i].send(toSend, 0, l);
}
}
делаем скриншот. квадратом в 100 пикселей (курсор в центре).