Directory

← Back

Webcam

HTML5 webcam for Vaadin 7

Author

Rating

Popularity

100+

Webcam allows you to capture images from the web camera. This add-on uses only JavaScript, so no Flash plug-in is required from the browser.

Currently works only with Google Chrome (also on Android) and Mozilla Firefox.

Sample code

private File targetFile;

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    // Create the webcam and assign a receiver.
    final Webcam webcam = new Webcam();
    webcam.setWidth("400px");
    webcam.setReceiver(new Receiver() {

        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
            try {
                targetFile = File.createTempFile(filename, ".jpeg");
                targetFile.deleteOnExit();
                return new FileOutputStream(targetFile);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    });

    // Add an event listener to be called after a successful capture.
    webcam.addCaptureSucceededListener(new CaptureSucceededListener() {

        @Override
        public void captureSucceeded(CaptureSucceededEvent event) {
            Image img = new Image("Captured image", new FileResource(
                    targetFile));
            img.setWidth("200px");
            layout.addComponent(img);
        }
    });

    // Add a button as an alternative way to capture.
    Button button = new Button(
            "Click the webcam viewfinder OR here to capture");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            webcam.capture();
        }
    });
    layout.addComponent(webcam);
    layout.addComponent(button);
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Add support for Chrome on Android.

Released
2015-04-15
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.0+
Browser
Firefox
Google Chrome
Android Browser

Webcam - Vaadin Add-on Directory

HTML5 webcam for Vaadin 7 Webcam - Vaadin Add-on Directory
Webcam allows you to capture images from the web camera. This add-on uses only JavaScript, so no Flash plug-in is required from the browser. Currently works only with Google Chrome (also on Android) and Mozilla Firefox.
Online