Example usage for com.google.gwt.html5.client CanvasElement setHeight

List of usage examples for com.google.gwt.html5.client CanvasElement setHeight

Introduction

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

Prototype

public final native void setHeight(int height) ;

Source Link

Usage

From source file:com.googlecode.gwtquake.client.GwtWebGLRenderer.java

License:Open Source License

public void setPicDataLowLevel(Image image, ImageElement img) {
    CanvasElement canvas = (CanvasElement) Document.get().createElement("canvas");
    int w = img.getWidth();
    int h = img.getHeight();
    canvas.setWidth(w);//from ww w.  ja v a2  s. com
    canvas.setHeight(h);
    //      canvas.getStyle().setProperty("border", "solid 1px green");
    canvas.getStyle().setDisplay(Display.NONE);
    Document.get().getBody().appendChild(canvas);
    CanvasRenderingContext2D ctx = canvas.getContext2D();
    ctx.drawImage(img, 0, 0);
    ImageData data = ctx.getImageData(0, 0, w, h);
    CanvasPixelArray pixels = data.getData();

    int count = w * h * 4;
    byte[] pic = new byte[count];
    for (int i = 0; i < count; i += 4) {
        pic[i + 3] = (byte) pixels.get(i + 3); // alpha, then bgr
        pic[i + 2] = (byte) pixels.get(i + 2);
        pic[i + 1] = (byte) pixels.get(i + 1);
        pic[i] = (byte) pixels.get(i);
    }

    image.setData(pic, w, h, 32);
}

From source file:com.googlecode.gwtquake.client.GwtWebGLRenderer.java

License:Open Source License

protected void debugLightmap(IntBuffer lightmapBuffer, int w, int h, float scale) {
    CanvasElement canvas = (CanvasElement) Document.get().createElement("canvas");
    canvas.setWidth(w);//from w  ww . j  a v a 2s .  c o m
    canvas.setHeight(h);
    Document.get().getBody().appendChild(canvas);
    ImageData id = canvas.getContext2D().createImageData(w, h);
    CanvasPixelArray pd = id.getData();
    for (int i = 0; i < w * h; i++) {
        int abgr = lightmapBuffer.get(i);
        pd.set(i * 4, abgr & 255);
        pd.set(i * 4 + 1, abgr & 255);
        pd.set(i * 4 + 2, abgr & 255);
        pd.set(i * 4 + 3, abgr & 255);
    }
    canvas.getContext2D().putImageData(id, 0, 0);
}