List of usage examples for com.google.gwt.canvas.dom.client Context2d drawImage
public final native void drawImage(ImageElement image, double dx, double dy) ;
From source file:anagram.client.Lens.java
License:Apache License
public void draw(Context2d back, Context2d front) { front.drawImage(back.getCanvas(), 0, 0); if (!GWT.isScript()) { // in devmode this effect is slow so we disable it here } else {/*from w w w . j a va2 s. c o m*/ ImageData frontData = front.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray frontPixels = frontData.getData(); ImageData backData = back.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray backPixels = backData.getData(); int srcIdx, dstIdx; for (int i = lensArray.length - 1; i >= 0; i--) { dstIdx = 4 * lensArray[i][0]; srcIdx = 4 * lensArray[i][1]; frontPixels.set(dstIdx + 0, backPixels.get(srcIdx + 0)); frontPixels.set(dstIdx + 1, backPixels.get(srcIdx + 1)); frontPixels.set(dstIdx + 2, backPixels.get(srcIdx + 2)); } front.putImageData(frontData, (int) (pos.x - radius), (int) (pos.y - radius)); } front.setStrokeStyle(strokeStyle); front.beginPath(); front.arc(pos.x, pos.y, radius, 0, Math.PI * 2, true); front.closePath(); front.stroke(); }
From source file:anagram.client.Logo.java
License:Apache License
void draw(Context2d context) { context.save();// w ww .j a v a 2s .co m context.translate(this.pos.x, this.pos.y); context.rotate(rot); context.drawImage(image, 0, 0); context.restore(); }
From source file:com.google.gwt.maeglin89273.shared.test.volcanogame.component.VolcanoWorld.java
@Override public void draw(Context2d context) { context.drawImage(background.getImage(), 0, 0); volcano.draw(context);//from w w w . ja v a 2 s . c o m context.save(); //context.setShadowBlur(12); for (Physical fireball : fireballs) { fireball.draw(context); } /*context.setShadowBlur(3); context.setShadowOffsetX(4); context.setShadowOffsetY(4); context.setShadowColor("rgba(65,65,65,0.3)");*/ context.drawImage(clouds.getImage(), 20, 30); context.restore(); }
From source file:com.google.gwt.sample.userwatcher.client.FileUploaderWidget_v2.java
private void upload(final Image image) { Canvas canvasTmp = Canvas.createIfSupported(); canvasTmp.setCoordinateSpaceHeight((int) image.getHeight()); canvasTmp.setCoordinateSpaceWidth((int) image.getWidth()); Context2d context = canvasTmp.getContext2d(); ImageElement imageElement = ImageElement.as(image.getElement()); context.drawImage(imageElement, 0, 0); String contentType = "image/jpeg"; String fileBase64 = canvasTmp.toDataUrl(contentType); UploadImage iu = new UploadImage(cp); iu.setFile(1234568759L, fileName, contentType, fileBase64); // TODO enable this if your testing it!!!!!!!!!! iu.upload();//from ww w . ja va 2 s.c o m iu.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { UploadImage u = (UploadImage) event.getSource(); int e = u.getChangeEvent(); fireChange(e); } }); }
From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java
public static ImageData scaleAndCropImage(Image image, double scaleToRatio, double sx, double sy, double sw, double sh) { Canvas canvasTmp = Canvas.createIfSupported(); //RootPanel.get().add(canvasTmp); Context2d context = canvasTmp.getContext2d(); double ch = (image.getHeight() * scaleToRatio) + 100; double cw = (image.getWidth() * scaleToRatio) + 100; canvasTmp.setCoordinateSpaceHeight((int) ch); canvasTmp.setCoordinateSpaceWidth((int) cw); ImageElement imageElement = ImageElement.as(image.getElement()); // tell it to scale image context.scale(scaleToRatio, scaleToRatio); // draw image to canvas // s = source // d = destination double dx = 0; double dy = 0; context.drawImage(imageElement, dx, dy); // get image data - if you go greater than the scaled image nothing will show up ImageData imageData = context.getImageData(sx, sy, sw, sh); return imageData; }
From source file:com.googlecode.mgwt.image.client.ImageConverter.java
License:Apache License
public void convert(final ImageResource resource, String color, final ImageConverterCallback imageConverterCallback) { if (color == null) { throw new IllegalArgumentException(); }// w w w. j a v a 2 s. com if (!color.startsWith("#")) { throw new IllegalArgumentException(); } color = maybeExpandColor(color); final int hexColor = Integer.parseInt(color.substring(1), 16); final int red = hexColor >> 16 & 0xFF; final int green = hexColor >> 8 & 0xFF; final int blue = hexColor & 0xFF; final int height = resource.getHeight(); final int width = resource.getWidth(); loadImage(resource.getSafeUri().asString(), width, height, new LoadImageCallback() { @Override public void onSuccess(ImageElement imageElement) { Canvas canvas = Canvas.createIfSupported(); canvas.getElement().setPropertyInt("height", height); canvas.getElement().setPropertyInt("width", width); Context2d context = canvas.getContext2d(); context.drawImage(imageElement, 0, 0); ImageData imageData = context.getImageData(0, 0, width, height); CanvasPixelArray canvasPixelArray = imageData.getData(); for (int i = 0; i < canvasPixelArray.getLength(); i += 4) { canvasPixelArray.set(i, red); canvasPixelArray.set(i + 1, green); canvasPixelArray.set(i + 2, blue); canvasPixelArray.set(i + 3, canvasPixelArray.get(i + 3)); } context.putImageData(imageData, 0, 0); imageConverterCallback.onSuccess(new ConvertedImageResource(canvas.toDataUrl("image/png"), resource.getWidth(), resource.getHeight())); } }); }
From source file:com.mecatran.otp.gwt.client.view.ItineraryDetailsWidget.java
License:Open Source License
/** * Build the background image for the widget, according to the mode. Draw * the mode image and a solid line below it with the route color (if in * transit mode) or a dotted line (if in road mode). Set the * background-image to the generated image for the given widget. *///from w ww .j av a2s . co m public static void styleComponentWithMode(final Widget widget, TransportMode mode, String color) { PlannerResources resources = PlannerResources.INSTANCE; ImageResource baseImage = null; boolean road = false; switch (mode) { case WALK: road = true; color = "#666666"; baseImage = resources.modeWalkPng(); break; case BICYCLE: road = true; color = "#23C30B"; baseImage = resources.modeBicyclePng(); break; case BICYCLE_RENTAL: road = true; color = "#23C30B"; baseImage = resources.modeBikeRentalPng(); break; case CAR: road = true; color = "#333333"; baseImage = resources.modeCarPng(); break; default: case BUS: baseImage = resources.modeBusPng(); break; case TRAM: baseImage = resources.modeTramPng(); break; case FERRY: baseImage = resources.modeFerryPng(); break; case GONDOLA: baseImage = resources.modeGondolaPng(); break; case PLANE: baseImage = resources.modePlanePng(); break; case RAIL: baseImage = resources.modeRailPng(); break; case SUBWAY: baseImage = resources.modeSubwayPng(); break; case TROLLEY: baseImage = resources.modeTrolleyPng(); break; } final String url = baseImage.getSafeUri().asString(); final Canvas canvas = Canvas.createIfSupported(); if (canvas != null) { int width = baseImage.getWidth(); int height = 1000; canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); final Context2d context = canvas.getContext2d(); context.setLineCap(LineCap.BUTT); if (road) { context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); for (int y = baseImage.getHeight(); y < 1000; y += 7) { context.moveTo(width / 2, y); context.lineTo(width / 2, y + 5); } context.stroke(); } else { context.setStrokeStyle(CssColor.make("#000000")); context.setLineWidth(5); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); } /* * HACK ALERT! Image.onLoad event does not fire up when using * internal resources (URL is internal data), but using the image * immediately does not work (image does not seems to be ready). We * defer the processing of the image rendering to a timer delayed a * bit. */ Timer timer = new Timer() { @Override public void run() { Image image = new Image(url); ImageElement e = ImageElement.as(image.getElement()); context.drawImage(e, 0, 0); String url2 = canvas.toDataUrl("image/png"); widget.getElement().getStyle().setBackgroundImage("url('" + url2 + "')"); } }; timer.schedule(500); } else { widget.getElement().getStyle().setBackgroundImage("url('" + url + "')"); } }
From source file:com.philbeaudoin.quebec.client.scene.Sprite.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { if (info == null || info.getElement() == null) { logger.log(Level.SEVERE, "Trying to draw a sprite with null image element."); }/*from w w w.j a va2s .co m*/ double sizeFactor = info.getSizeFactor(); ImageElement imageElement = info.getElement(); context.scale(sizeFactor, sizeFactor); context.drawImage(imageElement, -info.getWidth() / 2, -info.getHeight() / 2); }
From source file:edu.ycp.cs320.fokemon_webApp.client.LogoGroup.java
License:Open Source License
public void draw(Context2d back, Context2d front) { front.drawImage(back.getCanvas(), 0, 0); }
From source file:org.catrobat.html5player.client.Scene.java
License:Open Source License
/** * * @param imageElement/* w w w . j a v a2 s. c om*/ * @param brightness * @return Canvas canvas with the adjusted image */ private Canvas adjustImageBrightness(ImageElement imageElement, double brightness) { int width = imageElement.getWidth(); int height = imageElement.getHeight(); Canvas temp = Canvas.createIfSupported(); temp.setCoordinateSpaceWidth(width); temp.setCoordinateSpaceHeight(height); Context2d context = temp.getContext2d(); context.drawImage(imageElement, 0, 0); ImageData imageData = context.getImageData(0, 0, width, height); CanvasPixelArray pixelsData = imageData.getData(); int index = 0; System.out.println(pixelsData.getLength()); int brightnessAdj = (int) (255d * brightness) - 255; if (brightnessAdj != 0) { while (index < pixelsData.getLength()) { if ((index + 1) % 4 != 0) { int r = checkColorRange(pixelsData.get(index) + brightnessAdj); //red channel pixelsData.set(index, r); int g = checkColorRange(pixelsData.get(++index) + brightnessAdj); //green channel pixelsData.set(index, g); int b = checkColorRange(pixelsData.get(++index) + brightnessAdj); //blue channel pixelsData.set(index, b); index++; //alpha channel } index++; } } context.putImageData(imageData, 0, 0); return temp; }