List of usage examples for com.google.gwt.canvas.dom.client Context2d drawImage
public final native void drawImage(ImageElement image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) ;
From source file:com.google.gwt.maeglin89273.game.ashinyballonthecross.client.tutorial.component.BlueMark.java
@Override public void draw(Context2d context) { if (enabled) { context.save();/* w w w . ja v a 2s.com*/ context.translate(getX(), getY()); context.rotate(getAngle()); context.drawImage(spriteBlock.getSheetImage(), spriteBlock.getX(), spriteBlock.getY(), spriteBlock.getWidth(), spriteBlock.getHeight(), -getWidth() / 2, -getHeight() / 2, getWidth(), getHeight()); context.restore(); } }
From source file:com.google.gwt.maeglin89273.game.ashinyballonthecross.client.tutorial.component.StepBoard.java
@Override public void draw(Context2d context) { this.titleLabel.draw(context); context.drawImage(block.getSheetImage(), block.getX(), block.getY(), block.getWidth(), block.getHeight(), getX(), getY(), getWidth(), getHeight()); }
From source file:com.google.gwt.maeglin89273.game.ashinyballonthecross.client.tutorial.component.TasksList.java
@Override public void draw(Context2d context) { if (enabled) { context.drawImage(block.getSheetImage(), block.getX(), block.getY(), block.getWidth(), block.getHeight(), getLeftX(), getTopY(), getWidth(), getHeight()); for (CheckBox box : boxes) { box.draw(context);//w w w .j a v a 2s . c om } } }
From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java
public static ImageData cropImage(Image image, double sx, double sy, double sw, double sh) { Canvas canvasTmp = Canvas.createIfSupported(); Context2d context = canvasTmp.getContext2d(); canvasTmp.setCoordinateSpaceHeight((int) sh + 10); canvasTmp.setCoordinateSpaceWidth((int) sw + 10); ImageElement imageElement = ImageElement.as(image.getElement()); double dx = 0; double dy = 0; double dw = sw; double dh = sh; // draw image to canvas context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh); // get image data double w = sw; double h = sh; ImageData imageData = context.getImageData(0, 0, w, h); canvasTmp.removeFromParent();//from w w w .jav a 2 s . c om return imageData; }
From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java
/** * image - an ImageElement object// w w w . j a v a2s . c o m * sx - the x coordinate of the upper-left corner of the source rectangle sy - the y coordinate of the upper-left corner of the source rectangle sw - the width of the source rectangle sh - the width of the source rectangle dx - the x coordinate of the upper-left corner of the destination rectangle dy - the y coordinate of the upper-left corner of the destination rectangle dw - the width of the destination rectangle dh - the height of the destination rectangle */ public static ImageData scaleImage(Image image, double scaleToRatio) { //System.out.println("PanoTiler.scaleImag()e: scaleToRatio=" + scaleToRatio + " width=" + width + " x height=" + height); Canvas canvasTmp = Canvas.createIfSupported(); Context2d context = canvasTmp.getContext2d(); double ch = (image.getHeight() * scaleToRatio) + 100; // 100 is offset so it doesn't throw double cw = (image.getWidth() * scaleToRatio) + 100; canvasTmp.setCoordinateSpaceHeight((int) ch); canvasTmp.setCoordinateSpaceWidth((int) cw); ImageElement imageElement = ImageElement.as(image.getElement()); // s = source // d = destination double sx = 0; double sy = 0; double sw = imageElement.getWidth(); double sh = imageElement.getHeight(); double dx = 0; double dy = 0; double dw = imageElement.getWidth(); double dh = imageElement.getHeight(); // tell it to scale image context.scale(scaleToRatio, scaleToRatio); // draw image to canvas context.drawImage(imageElement, sx, sy, sw, sh, dx, dy, dw, dh); // get image data double w = dw * scaleToRatio; double h = dh * scaleToRatio; ImageData imageData = context.getImageData(0, 0, w, h); // this won't get the extra 100 return imageData; }
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.// w w w. j a va 2 s. com * * @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.primordion.xholon.io.GridPanel.java
License:Open Source License
/** * Draw a scaled subset of an image on the canvas. * @param ctx - A GWT Context2d object./*from ww w . j a v a2s. c om*/ * @param src - URI designating the source of this image (ex: "myimage.png"). * @param sx - the x coordinate of the upper-left corner of the source rectangle * @param sy - the y coordinate of the upper-left corner of the source rectangle * @param sw - the width of the source rectangle * @param sh - the width of the source rectangle * @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 sx, final double sy, final double sw, final double sh, 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, sx, sy, sw, sh, dx, dy, dw, dh); } }); img.setVisible(false); RootPanel.get().add(img); }
From source file:playn.html.HtmlImage.java
License:Apache License
@Override public void draw(Context2d ctx, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) { ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh); }
From source file:thothbot.parallax.core.client.renderers.WebGLRenderer.java
License:Open Source License
/** * Warning: Scaling through the canvas will only work with images that use * premultiplied alpha.//www .j a va2 s. c o m * * @param image the image element * @param maxSize the max size of absoluteWidth or absoluteHeight * * @return the image element (Canvas or Image) */ private Element clampToMaxSize(Element image, int maxSize) { int imgWidth = image.getOffsetWidth(); int imgHeight = image.getOffsetHeight(); if (imgWidth <= maxSize && imgHeight <= maxSize) return image; 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); return canvas; }