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

Source Link

Document

Draws an image.

Usage

From source file:org.cleanlogic.cesiumjs4gwt.showcase.examples.LoadImages.java

License:Apache License

@Override
public void buildPanel() {
    csVPanel = new ViewerPanel();

    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);//  w w w.ja v  a  2s  .  c  o m

    org.cesiumjs.cs.core.PinBuilder pinBuilder = new org.cesiumjs.cs.core.PinBuilder();
    pinBuilder.fromUrlPromise(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color_Overlay.png",
            Color.WHITE().withAlpha(0.0f), 256).then(new Fulfill<CanvasElement>() {
                @Override
                public void onFulfilled(CanvasElement value) {
                    BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
                    billboardOptions.image = new ConstantProperty<>(value.toDataUrl());
                    EntityOptions entityOptions = new EntityOptions();
                    entityOptions.name = "Pin billboard through fromUrl";
                    entityOptions.billboard = new BillboardGraphics(billboardOptions);
                    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(35, 35));
                    csVPanel.getViewer().entities().add(new Entity(entityOptions));
                }
            });

    Resource.fetchImage((ResourceImageOptions) ResourceImageOptions
            .create(GWT.getModuleBaseURL() + "images/Cesium_Logo_Color_Overlay.png"))
            .then(new Fulfill<JsImage>() {
                @Override
                public void onFulfilled(JsImage value) {
                    Canvas canvas = Canvas.createIfSupported();
                    canvas.setWidth(value.width + "px");
                    canvas.setHeight(value.height + "px");
                    Context2d context = canvas.getContext2d();
                    context.scale(0.1, 0.1);
                    context.drawImage((ImageElement) (Object) value, 0, 0);

                    BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
                    billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl());
                    EntityOptions entityOptions = new EntityOptions();
                    entityOptions.name = "Pin billboard through canvas";
                    entityOptions.billboard = new BillboardGraphics(billboardOptions);
                    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(45, 45));
                    csVPanel.getViewer().entities().add(new Entity(entityOptions));
                }
            });

    // CORS not loaded
    Resource.fetchImage((ResourceImageOptions) ResourceImageOptions
            .create("https://www.linux.org.ru/tango/img/games-logo.png")).then(new Fulfill<JsImage>() {
                @Override
                public void onFulfilled(JsImage value) {
                    Canvas canvas = Canvas.createIfSupported();
                    canvas.setWidth(value.width + "px");
                    canvas.setHeight(value.height + "px");
                    Context2d context = canvas.getContext2d();
                    context.scale(0.1, 0.1);
                    context.drawImage((ImageElement) (Object) value, 0, 0);

                    BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
                    billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl());
                    EntityOptions entityOptions = new EntityOptions();
                    entityOptions.name = "Pin billboard CORS";
                    entityOptions.billboard = new BillboardGraphics(billboardOptions);
                    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(55, 55));
                    csVPanel.getViewer().entities().add(new Entity(entityOptions));
                }
            });

    // Cors not loaded!
    final JsImage imageAmz = new JsImage();
    imageAmz.crossOrigin = "*";
    imageAmz.onload = new JsImage.Listener() {
        @Override
        public void function() {
            Cesium.log(imageAmz);
            /*Canvas canvas = Canvas.createIfSupported();
            canvas.setWidth(imageAmz.width + "px");
            canvas.setHeight(imageAmz.height + "px");
            Context2d context = canvas.getContext2d();
            context.scale(0.1, 0.1);
            context.drawImage((ImageElement) (Object) imageAmz, 0, 0);*/
            BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
            billboardOptions.image = new ConstantProperty<>(imageAmz);
            //billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl("image/png"));
            EntityOptions entityOptions = new EntityOptions();
            entityOptions.name = "Pin billboard CORS";
            entityOptions.billboard = new BillboardGraphics(billboardOptions);
            entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(65, 65));
            csVPanel.getViewer().entities().add(new Entity(entityOptions));
        }
    };
    imageAmz.src = "https://d1.awsstatic.com/products/cloudfront/cloudfront-100_PoP_600x400.4a1edd6022833c54c41370ad9f615ae818350a23.png";

    // Worked, have Access-Control-Allow-Origin: *
    final JsImage imageWiki = new JsImage();
    imageWiki.crossOrigin = "*";
    imageWiki.onload = new JsImage.Listener() {
        @Override
        public void function() {
            Cesium.log(imageWiki);
            Canvas canvas = Canvas.createIfSupported();
            canvas.setWidth(imageWiki.width + "px");
            canvas.setHeight(imageWiki.height + "px");
            Context2d context = canvas.getContext2d();
            context.drawImage((ImageElement) (Object) imageWiki, 0, 0);
            BillboardGraphicsOptions billboardOptions = new BillboardGraphicsOptions();
            billboardOptions.image = new ConstantProperty<>(canvas.toDataUrl("image/png"));
            EntityOptions entityOptions = new EntityOptions();
            entityOptions.name = "Pin billboard CORS";
            entityOptions.billboard = new BillboardGraphics(billboardOptions);
            entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(75, 75));
            csVPanel.getViewer().entities().add(new Entity(entityOptions));
        }
    };
    imageWiki.src = "https://ru.wikipedia.org/static/images/project-logos/ruwiki-2x.png";

    contentPanel.add(new HTML("<p>Cluster labels, billboards and points.</p>"));
    contentPanel.add(aPanel);

    initWidget(contentPanel);
}

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

License:Open Source License

/**
 * Draw an image on the canvas./*from   w w  w.  j  av  a  2  s  .c  om*/
 * TODO this works, but the image flickers each time step
 * TODO each time step, a new img tag is added to RootPanel (the HTML body)
 * @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
 */
protected void drawImage(final Context2d ctx, final String src, final double dx, final double dy) {
    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);
        }
    });
    img.setVisible(false);
    RootPanel.get().add(img);
}

From source file:playn.html.HtmlCanvasLayerCanvas.java

License:Apache License

@Override
void paint(Context2d ctx, float parentAlpha) {
    ctx.save();/*from ww  w.j a v a  2s.  c  om*/
    transform(ctx);

    ctx.setGlobalAlpha(parentAlpha * alpha);
    ctx.drawImage(canvas.canvas(), 0, 0);

    ctx.restore();
}

From source file:playn.html.HtmlSurfaceLayerCanvas.java

License:Apache License

@Override
void paint(Context2d ctx, float parentAlpha) {
    if (!visible())
        return;//  w  w w. ja va 2  s.c o m

    ctx.save();
    transform(ctx);

    ctx.setGlobalAlpha(parentAlpha * alpha);
    ctx.drawImage(canvas.canvas(), 0, 0);

    ctx.restore();
}

From source file:stroom.pipeline.structure.client.view.PipelineElementRenderer.java

License:Apache License

private void drawImage(final Context2d ctx, final double x, final double y, final ImageElement imageElement,
        final PipelineElement element) {
    if (imageElement != null) {
        ctx.drawImage(imageElement, x, y - 12);
        drawText(ctx, x + imageElement.getWidth() + IMAGE_MARGIN, y, element);

    } else {//w  ww.j ava  2s  .  c  o  m
        // We don't have an image so just render text.
        drawText(ctx, x, y, element);
    }
}

From source file:web.diva.client.somclust.view.MaxTreeZoomImage.java

public void buffer(Context2d back, Context2d front) {
    front.beginPath();/* ww  w  .j  a  va 2  s .co m*/
    front.clearRect(0, 0, width, height);
    front.drawImage(back.getCanvas(), 0, 0);
}