Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide utility methods to capture image in specific format
closes #15
- Loading branch information
Showing
7 changed files
with
190 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
webcam-capture/src/example/java/com/github/sarxos/webcam/DifferentFileFormatsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import com.github.sarxos.webcam.util.ImageUtils; | ||
|
||
|
||
public class DifferentFileFormatsExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
Webcam webcam = Webcam.getDefault(); | ||
|
||
// save files directly to disk | ||
|
||
// creates test1.bmp | ||
WebcamUtils.capture(webcam, "test1", ImageUtils.FORMAT_BMP); | ||
// creates test1.gif | ||
WebcamUtils.capture(webcam, "test1", ImageUtils.FORMAT_GIF); | ||
// creates test1.jpg | ||
WebcamUtils.capture(webcam, "test1", ImageUtils.FORMAT_JPG); | ||
// creates test1.png | ||
WebcamUtils.capture(webcam, "test1", ImageUtils.FORMAT_PNG); | ||
// creates test1.wbmp | ||
WebcamUtils.capture(webcam, "test1", ImageUtils.FORMAT_WBMP); | ||
|
||
// this is equivalent of this code | ||
|
||
// creates test2.bmp | ||
WebcamUtils.capture(webcam, "test2", "bmp"); | ||
// creates test2.gif | ||
WebcamUtils.capture(webcam, "test2", "gif"); | ||
// creates test2.jpg | ||
WebcamUtils.capture(webcam, "test2", "jpg"); | ||
// creates test2.png | ||
WebcamUtils.capture(webcam, "test2", "png"); | ||
// creates test2.wbmp | ||
WebcamUtils.capture(webcam, "test2", "wbmp"); | ||
|
||
// NOTE !!! | ||
// you can use any format you want until there is a ImageIO plugin | ||
// installed which supports it | ||
|
||
// get image as bytes array / bytes buffer | ||
|
||
// save image in JPG format and return as array of bytes | ||
byte[] bytes = WebcamUtils.getImageBytes(webcam, "jpg"); | ||
System.out.println("Bytes length: " + bytes.length); | ||
|
||
// save image in JPG format and return as byte buffer | ||
ByteBuffer buffer = WebcamUtils.getImageByteBuffer(webcam, "jpg"); | ||
System.out.println("Buffer length: " + buffer.capacity()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamResolution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.sarxos.webcam; | ||
|
||
import java.awt.Dimension; | ||
|
||
|
||
public enum WebcamResolution { | ||
|
||
QQVGA(176, 144), | ||
QVGA(320, 240), | ||
CIF(352, 288), | ||
HVGA(480, 400), | ||
VGA(640, 480), | ||
PAL(768, 576), | ||
SVGA(800, 600), | ||
XGA(1024, 768), | ||
HD720(1280, 720), | ||
WXGA(1280, 768), | ||
SXGA(1280, 1024), | ||
UXGA(1600, 1200), | ||
QXGA(2048, 1536); | ||
|
||
private Dimension size = null; | ||
|
||
private WebcamResolution(int width, int height) { | ||
this.size = new Dimension(width, height); | ||
} | ||
|
||
public Dimension getSize() { | ||
return size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters