Example usage for com.google.gwt.dom.client CanvasElement toDataUrl

List of usage examples for com.google.gwt.dom.client CanvasElement toDataUrl

Introduction

In this page you can find the example usage for com.google.gwt.dom.client CanvasElement toDataUrl.

Prototype

public final native String toDataUrl(String type) ;

Source Link

Document

Returns a data URL for the current content of the canvas element, with a specified type.

Usage

From source file:gwt.material.design.addins.client.camera.MaterialCameraCapture.java

License:Apache License

/**
 * Native call to capture the frame of the video stream.
 *//*from  w w w.  ja v  a2s.  c  o m*/
protected String nativeCaptureToDataURL(CanvasElement canvas, Element element, String mimeType) {
    VideoElement videoElement = (VideoElement) element;
    int width = videoElement.getVideoWidth();
    int height = videoElement.getVideoHeight();
    if (Double.isNaN(width) || Double.isNaN(height)) {
        width = videoElement.getClientWidth();
        height = videoElement.getClientHeight();
    }
    canvas.setWidth(width);
    canvas.setHeight(height);
    Context2d context = canvas.getContext2d();
    context.drawImage(videoElement, 0, 0, width, height);
    return canvas.toDataUrl(mimeType);
}