Example usage for com.google.gwt.canvas.dom.client Context2d drawImage

List of usage examples for com.google.gwt.canvas.dom.client Context2d drawImage

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d drawImage.

Prototype

public final native void drawImage(ImageElement image, double dx, double dy, double dw, double dh) ;

Source Link

Document

Draws a scaled image.

Usage

From source file:org.geomajas.gwt2.example.client.sample.rendering.CanvasImageElement.java

License:Open Source License

@Override
public void paint(Canvas canvas, Matrix matrix) {
    /*/*  w w w  . j  ava2 s.  co m*/
    * paint image on canvas based on the original and with the transformations of the matrix.
    * */
    Context2d context2d = canvas.getContext2d();
    context2d.save();
    boolean xReversal = matrix.getXx() < 0;
    boolean yReversal = matrix.getYy() < 0;
    context2d.scale(xReversal ? -1 : 1, yReversal ? -1 : 1);
    double xValue = xReversal ? box.getMaxX() * -1 : box.getX();
    double yValue = yReversal ? box.getMaxY() * -1 : box.getY();
    context2d.drawImage(hiddenImageCanvas.getCanvasElement(), xValue, yValue, box.getWidth(), box.getHeight());
    context2d.restore();
}

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;//ww  w  .  j a v a  2  s  .com
    return this;
}

From source file:org.primordion.xholon.io.GridPanel.java

License:Open Source License

/**
 * Draw a scaled image on the canvas.// w ww  .j  av a 2 s . co m
 * @param ctx - A GWT Context2d object.
 * @param src - URI designating the source of this image (ex: "myimage.png").
 * @param dx - the x coordinate of the upper-left corner of the destination rectangle
 * @param dy - the y coordinate of the upper-left corner of the destination rectangle
 * @param dw - the width of the destination rectangle
 * @param dh - the height of the destination rectangle
 */
protected void drawImage(final Context2d ctx, final String src, final double dx, final double dy,
        final double dw, final double dh) {
    Image img = new Image(src);
    final ImageElement image = ImageElement.as(img.getElement());
    img.addLoadHandler(new LoadHandler() {
        @Override
        public void onLoad(LoadEvent event) {
            ctx.drawImage(image, dx, dy, dw, dh);
        }
    });
    img.setVisible(false);
    RootPanel.get().add(img);
}

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;
}

From source file:thothbot.parallax.loader.shared.JsonLoader.java

License:Open Source License

private Texture create_texture(String sourceFile, List<Integer> repeat, List<Double> offset,
        List<JsoTextureWrapMode> wrap, int anisotropy) {
    boolean isCompressed = sourceFile.toLowerCase().endsWith(".dds");
    final String fullPath = getTexturePath() + sourceFile;

    final Texture texture;

    if (isCompressed) {
        texture = new CompressedTexture(fullPath);
    } else {/*from w  ww  .j a  v  a2  s .  com*/
        texture = new Texture(fullPath, new Texture.ImageLoadHandler() {

            @Override
            public void onImageLoad(Texture texture) {
                int oWidth = texture.getImage().getOffsetWidth();
                int oHeight = texture.getImage().getOffsetHeight();

                if (!Mathematics.isPowerOfTwo(oWidth) || !Mathematics.isPowerOfTwo(oHeight)) {
                    CanvasElement canvas = Document.get().createElement("canvas").cast();
                    int width = Mathematics.getNextHighestPowerOfTwo(oWidth);
                    int height = Mathematics.getNextHighestPowerOfTwo(oHeight);
                    canvas.setWidth(width);
                    canvas.setHeight(height);

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

                    texture.setImage(canvas);
                }

                texture.setNeedsUpdate(true);
            }
        });
        texture.setNeedsUpdate(false);
    }

    if (repeat != null) {
        texture.getRepeat().set(repeat.get(0), repeat.get(1));

        if (repeat.get(0) != 1)
            texture.setWrapS(TextureWrapMode.REPEAT);
        if (repeat.get(1) != 1)
            texture.setWrapT(TextureWrapMode.REPEAT);
    }

    if (offset != null) {
        texture.getOffset().set(offset.get(0), offset.get(1));
    }

    if (wrap != null) {
        if (wrap.get(0) != null)
            texture.setWrapS(wrap.get(0).getValue());
        if (wrap.get(1) != null)
            texture.setWrapT(wrap.get(1).getValue());
    }

    if (anisotropy > 0) {
        texture.setAnisotropy(anisotropy);
    }
    return texture;
}