-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenCapture.java
More file actions
101 lines (87 loc) · 3.25 KB
/
ScreenCapture.java
File metadata and controls
101 lines (87 loc) · 3.25 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
package com.company;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;
public class ScreenCapture {
private BufferedImage screenFullImage = null;
private ObjectOutputStream out = null;
private ObjectOutputStream outSound = null;
private Socket source = null;
int port = 0;
String host;
private byte[] ImageBytes = null;
public static void main(String[] args){
ScreenCapture t = new ScreenCapture();
t.FullScreenStream(24);
System.exit(0);
}
public void FullScreenStream(int FrameRate){
ConnectServer();
long start = System.currentTimeMillis();
try{
Thread.sleep(2000);
}catch (InterruptedException E){
}
Thread a = new CaputureScreen();
a.start();
//MouseKeyClient mouse = new MouseKeyClient(port,host);
//KeyboardClient keyboard = new KeyboardClient(port,host);
try{
Thread.sleep(1000);
} catch (InterruptedException E){
}
while(true){
try {
out.writeObject(CompressionUtils.compress(toByteArrayAutoClosable( ( (CaputureScreen)a).pic, "jpeg")));
} catch (IOException E){
System.out.println(E);
}
}
//FullStreamDebug(start, FrameRate, i);
}
public void FullStreamDebug(long start, int FrameRate, int totalFrames){
long end = System.currentTimeMillis();
double totalTime = (double)(end - start)/1000;
double EffectiveFrameRate = (totalFrames/totalTime);
System.out.println("Start: " + start);
System.out.println("End: " + end);
System.out.println("Total Time: " + totalTime);
System.out.println("Total Frames: " + totalFrames);
System.out.println("The effective frame-rate: " + EffectiveFrameRate);
System.out.println("Frame-rate desired: " + FrameRate);
System.out.println("Frame-Division Loss: " + (1000 - ((1000/FrameRate))));
}
public void ConnectServer() {
Scanner in = new Scanner(System.in);
System.out.println("Please enter server Name: ");
host = in.nextLine();
System.out.println("Please enter server Port: ");
port = in.nextInt();
try {
source = new Socket(host, port);
out = new ObjectOutputStream(source.getOutputStream());
} catch (IOException E) {
System.out.println(E);
}
}
private byte[] toByteArrayAutoClosable(BufferedImage image, String type) throws IOException {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()){
ImageIO.write(image, type, out);
return out.toByteArray();
}
}
public class CaputureScreen extends Thread {
protected BufferedImage pic;
private Rectangle screenRect = new Rectangle(1920,1080);
public void run() {
while(true) {
pic = JNAScreenShot.getScreenshot(screenRect);
}
}
}
}