Skip to content

Commit d18bfa9

Browse files
committed
Add README.md in screen capture driver
1 parent cc6087c commit d18bfa9

File tree

6 files changed

+142
-22
lines changed

6 files changed

+142
-22
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# webcam-capture-driver-screencapture
2+
3+
This is capture driver which is able to capture video feed from your screen devices. It uses AWT Robot under
4+
the hood and it's is directly limited by its performance. Every screen device connected to your computer will
5+
be abstracted as a separate webcam device.
6+
7+
## Maven
8+
9+
Stable:
10+
11+
```xml
12+
<dependency>
13+
<groupId>com.github.sarxos</groupId>
14+
<artifactId>webcam-capture-driver-screencapture</artifactId>
15+
<version>0.3.12</version>
16+
</dependency>
17+
```
18+
19+
Snapshot:
20+
21+
```xml
22+
<repository>
23+
<id>Sonatype OSS Snapshot Repository</id>
24+
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
25+
</repository>
26+
```
27+
```xml
28+
<dependency>
29+
<groupId>com.github.sarxos</groupId>
30+
<artifactId>webcam-capture-driver-screencapture</artifactId>
31+
<version>0.3.13-SNAPSHOT</version>
32+
</dependency>
33+
```
34+
35+
## How To Use
36+
37+
Set capture driver before you start using Webcam class:
38+
39+
```java
40+
import java.awt.Dimension;
41+
import java.awt.FlowLayout;
42+
43+
import javax.swing.JFrame;
44+
45+
import com.github.sarxos.webcam.Webcam;
46+
import com.github.sarxos.webcam.WebcamPanel;
47+
import com.github.sarxos.webcam.WebcamPanel.DrawMode;
48+
import com.github.sarxos.webcam.WebcamResolution;
49+
import com.github.sarxos.webcam.ds.gstreamer.ScreenCaptureDriver;
50+
51+
52+
public class WebcamPanelExample {
53+
54+
static {
55+
Webcam.setDriver(new ScreenCaptureDriver());
56+
}
57+
58+
public static void main(String[] args) throws InterruptedException {
59+
60+
final JFrame window = new JFrame("Screen Capture Example");
61+
window.setResizable(true);
62+
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
63+
window.getContentPane().setLayout(new FlowLayout());
64+
65+
final Dimension resolution = WebcamResolution.QVGA.getSize();
66+
67+
for (final Webcam webcam : Webcam.getWebcams()) {
68+
69+
webcam.setCustomViewSizes(resolution);
70+
webcam.setViewSize(resolution);
71+
webcam.open();
72+
73+
final WebcamPanel panel = new WebcamPanel(webcam);
74+
panel.setFPSDisplayed(true);
75+
panel.setDrawMode(DrawMode.FIT);
76+
panel.setImageSizeDisplayed(true);
77+
panel.setPreferredSize(resolution);
78+
79+
window.getContentPane().add(panel);
80+
}
81+
82+
window.pack();
83+
window.setVisible(true);
84+
}
85+
}
86+
```
87+
88+
## Examples
89+
90+
Please check [this](https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-drivers/driver-screencapture/src/example/java) directory for more examples.
91+
92+
## Known Problems
93+
94+
1. I noticed this on my Ubuntu Linux - black regions appears in place where other application (e.g. Cairo Dock)
95+
render OpenGL content. I don't know about any workaround or solution for this problem. Not verified on Mac and Windows.
96+
Please report [new issue](https://github.com/sarxos/webcam-capture/issues/new) if you know how to fix this.
97+
98+
## Capture Driver License
99+
100+
Copyright (C) 2012 - 2018 Bartosz Firyn <https://github.com/sarxos> and contributors
101+
102+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
103+
104+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
105+
106+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
107+
63.9 KB
Loading
113 KB
Loading

webcam-capture-drivers/driver-screencapture/src/example/java/WebcamPanelExample.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.github.sarxos.webcam.Webcam;
77
import com.github.sarxos.webcam.WebcamPanel;
88
import com.github.sarxos.webcam.WebcamPanel.DrawMode;
9+
import com.github.sarxos.webcam.WebcamResolution;
910
import com.github.sarxos.webcam.ds.gstreamer.ScreenCaptureDriver;
1011

1112

@@ -15,20 +16,26 @@ public class WebcamPanelExample {
1516
Webcam.setDriver(new ScreenCaptureDriver());
1617
}
1718

18-
public static void main(String[] args) {
19+
public static void main(String[] args) throws InterruptedException {
1920

2021
final JFrame window = new JFrame("Screen Capture Example");
2122
window.setResizable(true);
2223
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2324
window.getContentPane().setLayout(new FlowLayout());
2425

25-
for (Webcam webcam : Webcam.getWebcams()) {
26+
final Dimension resolution = WebcamResolution.QVGA.getSize();
2627

27-
WebcamPanel panel = new WebcamPanel(webcam);
28+
for (final Webcam webcam : Webcam.getWebcams()) {
29+
30+
webcam.setCustomViewSizes(resolution);
31+
webcam.setViewSize(resolution);
32+
webcam.open();
33+
34+
final WebcamPanel panel = new WebcamPanel(webcam);
2835
panel.setFPSDisplayed(true);
2936
panel.setDrawMode(DrawMode.FIT);
3037
panel.setImageSizeDisplayed(true);
31-
panel.setPreferredSize(new Dimension(300, 200));
38+
panel.setPreferredSize(resolution);
3239

3340
window.getContentPane().add(panel);
3441
}

webcam-capture-drivers/driver-screencapture/src/example/java/WebcamPanelSubViewExample.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,29 @@ public class WebcamPanelSubViewExample {
2121
Webcam.setDriver(new WebcamCompositeDriver(new WebcamDefaultDriver(), new ScreenCaptureDriver()));
2222
}
2323

24-
private final Dimension size = WebcamResolution.QQVGA.getSize();
24+
private final Webcam webcam = Webcam.getWebcams().get(0);
2525
private final Webcam screen = Webcam.getWebcams().get(1);
26-
private final WebcamPanel panel = new WebcamPanel(screen);
26+
private final Dimension webcamSize = WebcamResolution.QVGA.getSize();
27+
private final Dimension screenSize = WebcamResolution.QHD.getSize();
28+
private final WebcamPanel panel = new WebcamPanel(screen, false);
2729
private final Painter dp = panel.getDefaultPainter();
2830
private final JFrame window = new JFrame("Test");
2931

3032
private final class SubViewPainter implements Painter {
3133

32-
private final Webcam webcam = Webcam.getDefault();
33-
private final int x = 619;
34-
private final int y = 437;
35-
private final int w = size.width;
36-
private final int h = size.height;
37-
38-
public SubViewPainter() {
39-
webcam.setViewSize(size);
40-
webcam.open();
41-
}
34+
private final int x = screenSize.width - webcamSize.width - 5;
35+
private final int y = screenSize.height - webcamSize.height - 21;
36+
private final int w = webcamSize.width;
37+
private final int h = webcamSize.height;
4238

4339
@Override
4440
public void paintImage(WebcamPanel owner, BufferedImage image, Graphics2D g2) {
41+
4542
dp.paintImage(owner, image, g2);
43+
4644
g2.setColor(Color.BLACK);
4745
g2.drawRect(x - 1, y - 1, w + 1, h + 1);
48-
g2.drawImage(webcam.getImage(), x, y, w, h, null);
46+
g2.drawImage(webcam.getImage(), x, y, null);
4947
}
5048

5149
@Override
@@ -56,21 +54,29 @@ public void paintPanel(WebcamPanel panel, Graphics2D g2) {
5654

5755
public WebcamPanelSubViewExample() {
5856

57+
screen.setCustomViewSizes(screenSize);
58+
screen.setViewSize(screenSize);
5959
screen.open(true);
6060

61+
panel.setFPSLimit(30);
6162
panel.setFPSDisplayed(true);
62-
panel.setDrawMode(DrawMode.FIT);
63+
panel.setDrawMode(DrawMode.NONE);
6364
panel.setImageSizeDisplayed(true);
64-
panel.setFPSDisplayed(true);
6565
panel.setPainter(new SubViewPainter());
66-
panel.setPreferredSize(new Dimension(800, 600));
66+
panel.setPreferredSize(screenSize);
67+
68+
webcam.setViewSize(webcamSize);
69+
webcam.open(true);
6770

68-
window.setResizable(true);
71+
window.setPreferredSize(screenSize);
72+
window.setResizable(false);
6973
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
74+
window.setLayout(null);
7075
window.setContentPane(panel);
7176
window.pack();
7277
window.setVisible(true);
7378

79+
panel.start();
7480
}
7581

7682
public static void main(String[] args) {

webcam-capture-drivers/driver-screencapture/src/main/java/com/github/sarxos/webcam/ds/gstreamer/ScreenCaptureDevice.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public BufferedImage getImage() {
8080
final int height = resolution.height;
8181

8282
if (screen.getWidth() == width && screen.getHeight() == height) {
83-
return screen; // No need for adaption
83+
return screen; // No need for adaptation
8484
}
8585

8686
final BufferedImage img = new BufferedImage(width, height, screen.getType());

0 commit comments

Comments
 (0)