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

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

Introduction

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

Prototype

public final native Context2d getContext2d() ;

Source Link

Document

Returns a 2D rendering context.

Usage

From source file:com.yocalist.client.ui.GwtCanvasView.java

License:Apache License

public GwtCanvasView(CanvasElement element, String data, HasText progress) {
    context = element.getContext2d();
    this.data = data;
    this.progress = progress;
}

From source file:forplay.html.HtmlCanvas.java

License:Apache License

HtmlCanvas(CanvasElement canvas, int width, int height) {
    this.canvas = canvas;
    this.width = width;
    this.height = height;
    canvas.setWidth(width);//from   w w w.jav  a2s .  c  o  m
    canvas.setHeight(height);
    ctx = canvas.getContext2d();
}

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 ww  . jav  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);
}

From source file:gwt.material.design.addins.client.signature.MaterialSignaturePad.java

License:Apache License

protected void applyResize() {
    CanvasElement element = getElement().cast();
    double ratio = getRatio();
    element.setWidth((int) (getOffsetWidth() * ratio));
    element.setHeight((int) (getOffsetHeight() * ratio));
    element.getContext2d().scale(ratio, ratio);
    getSignaturePad().clear();//w w  w .  ja v a2  s  .  c  o m
}

From source file:org.cruxframework.crux.core.client.image.ImageProcessor.java

License:Apache License

/**
 * Resize the internal image/* w w  w. jav a2s  . c om*/
 * @param width
 * @param height
 */
public void resize(int width, int height) {
    assert (image != null || this.canvas != null) : "You must load an image first";

    CanvasElement canvas = Document.get().createCanvasElement().cast();
    canvas.setWidth(width);
    canvas.setHeight(height);
    if (image != null) {
        canvas.getContext2d().drawImage(image.asImageElement(), 0, 0, width, height);
    } else {
        canvas.getContext2d().drawImage(this.canvas, 0, 0, this.canvas.getWidth(), this.canvas.getHeight(), 0,
                0, width, height);
    }

    this.canvas = canvas;
    image = null;
}

From source file:org.parallax3d.parallax.graphics.textures.PixmapTextureData.java

License:Open Source License

/**
 * Warning: Scaling through the canvas will only work with images that use
 * premultiplied alpha./*from www. j av  a 2 s.c o  m*/
 *
 * @param maxSize  the max size of absoluteWidth or absoluteHeight
 *
 * @return a new Image, or the same one if no clamping was necessary
 */
public PixmapTextureData clampToMaxSize(int maxSize) {
    int imgWidth = image.getOffsetWidth();
    int imgHeight = image.getOffsetHeight();

    if (imgWidth <= maxSize && imgHeight <= maxSize)
        return this;

    int maxDimension = Math.max(imgWidth, imgHeight);
    int newWidth = (int) Math.floor(imgWidth * maxSize / maxDimension);
    int newHeight = (int) Math.floor(imgHeight * maxSize / maxDimension);

    CanvasElement canvas = Document.get().createElement("canvas").cast();
    canvas.setWidth(newWidth);
    canvas.setHeight(newHeight);

    Context2d context = canvas.getContext2d();
    context.drawImage((ImageElement) image, 0, 0, imgWidth, imgHeight, 0, 0, newWidth, newHeight);

    image.getParentElement().appendChild(canvas);
    image.removeFromParent();
    image = canvas;

    return this;
}

From source file:org.parallax3d.parallax.graphics.textures.PixmapTextureData.java

License:Open Source License

@Override
public PixmapTextureData toPowerOfTwo() {
    if (isPowerOfTwo())
        return this;

    int width = image.getOffsetWidth();
    int height = image.getOffsetHeight();

    CanvasElement canvas = Document.get().createElement("canvas").cast();

    // Scale up the texture to the next highest power of two dimensions.
    canvas.setWidth(Mathematics.getNextHighestPowerOfTwo(width));
    canvas.setHeight(Mathematics.getNextHighestPowerOfTwo(height));

    Context2d context = canvas.getContext2d();
    context.drawImage((ImageElement) image, 0, 0, width, height);

    image = canvas;//from  ww  w.j a v a2s. c  om
    return this;
}

From source file:playn.html.HtmlCanvas.java

License:Apache License

HtmlCanvas(CanvasElement canvas, float width, float height) {
    this(canvas, canvas.getContext2d(), width, height);
    canvas.setWidth(MathUtil.iceil(width));
    canvas.setHeight(MathUtil.iceil(height));
}

From source file:playn.html.HtmlImage.java

License:Apache License

ImageElement subImageElement(float x, float y, float width, float height) {
    CanvasElement canvas = Document.get().createElement("canvas").<CanvasElement>cast();
    canvas.setWidth(MathUtil.iceil(width));
    canvas.setHeight(MathUtil.iceil(height));
    canvas.getContext2d().drawImage(img, x, y, width, height, 0, 0, width, height);
    return canvas.cast();
}

From source file:thothbot.parallax.core.client.renderers.WebGLRenderer.java

License:Open Source License

private CanvasElement createPowerOfTwoImage(Element image) {
    int width = image.getOffsetWidth();
    int height = image.getOffsetHeight();

    CanvasElement canvas = Document.get().createElement("canvas").cast();

    // Scale up the texture to the next highest power of two dimensions.
    canvas.setWidth(Mathematics.getNextHighestPowerOfTwo(width));
    canvas.setHeight(Mathematics.getNextHighestPowerOfTwo(height));

    Context2d context = canvas.getContext2d();
    context.drawImage((ImageElement) image, 0, 0, width, height);

    return canvas;
}