List of usage examples for com.google.gwt.canvas.client Canvas setCoordinateSpaceHeight
public void setCoordinateSpaceHeight(int height)
From source file:com.example.texture_mapping.client.Texture_mapping.java
License:Apache License
public void onModuleLoad() { // HTML ben//from w w w .j av a 2s . c om Grid grid = new Grid(3, 3); grid.setBorderWidth(1); int numRows = grid.getRowCount(); int numColumns = grid.getColumnCount(); for (int row = 0; row < numRows; row++) { for (int col = 0; col < numColumns; col++) { grid.setWidget(row, col, new Image(PlaceholderImages.INSTANCE.myImage())); } } RootPanel.get().add(grid); // WebGL final Canvas webGLCanvas = Canvas.createIfSupported(); webGLCanvas.setCoordinateSpaceHeight(500); // ToDo: AutoSize webGLCanvas.setCoordinateSpaceWidth(500); glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl"); if (glContext == null) { glContext = (WebGLRenderingContext) webGLCanvas.getContext("experimental-webgl"); } if (glContext == null) { Window.alert("Sorry, Your Browser doesn't support WebGL!"); } glContext.viewport(0, 0, 500, 500); RootPanel.get("gwtGL").add(webGLCanvas); start(); }
From source file:com.google.gwt.sample.userwatcher.client.FileUploaderWidget_v2.java
private void drawThumbToScreen(Image image) { int size = 75; int width = image.getWidth(); int height = image.getHeight(); double scaleToRatio = 0.50D; // TODO oops, getting image loading problem. event loading, fix later... ImageData imageDataForThumb = ImageUtils.scaleImage(image, scaleToRatio); // for debugging Canvas canvasTmp = Canvas.createIfSupported(); canvasTmp.setCoordinateSpaceHeight((int) imageDataForThumb.getHeight()); canvasTmp.setCoordinateSpaceWidth((int) imageDataForThumb.getWidth()); Context2d context = canvasTmp.getContext2d(); context.putImageData(imageDataForThumb, 0, 0); pThumb.add(canvasTmp);/* ww w . j a v a 2s. c o m*/ canvasTmp.addStyleName("test2"); }
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 w w w . ja va 2 s . c om 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 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 ww .jav a 2s . c om*/ return imageData; }
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.google.gwt.sample.userwatcher.client.ImageUtils.java
/** * for debugging//from w ww . ja va2s .c om * * @param imageData */ public static void addImageToScreen(ImageData imageData) { Canvas canvasTmp = Canvas.createIfSupported(); canvasTmp.setCoordinateSpaceHeight((int) imageData.getHeight() + 10); canvasTmp.setCoordinateSpaceWidth((int) imageData.getWidth() + 10); Context2d context = canvasTmp.getContext2d(); context.putImageData(imageData, 0, 0); //flexTable.setWidget(r, c, canvasTmp); RootPanel.get().add(canvasTmp); }
From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java
/** * image - an ImageElement object//from w w w . j a v a2 s . co 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:com.google.gwt.sample.userwatcher.client.ImageUtils.java
public static ImageData cropImage(ImageData imageData, double sx, double sy, double sw, double sh) { Canvas canvasTmp = Canvas.createIfSupported(); canvasTmp.setStyleName("mainCanvas"); Context2d context = canvasTmp.getContext2d(); canvasTmp.setCoordinateSpaceHeight((int) imageData.getHeight() + 10); canvasTmp.setCoordinateSpaceWidth((int) imageData.getWidth() + 10); // draw image to canvas context.putImageData(imageData, 0, 0); // get image data //imageData = context.getImageData(0, 0, imageData.getWidth(), imageData.getHeight()); ImageData newImageData = context.getImageData(sx, sy, sw, sh); return newImageData; }
From source file:com.lambourg.webgallery.client.widgets.TitleBarIcon.java
License:GNU General Public License
private void draw() { Context2d ctx;/* ww w .ja va2 s . co m*/ Canvas buffer = Canvas.createIfSupported(); Image img; int size = Style.toPixelRatio(Style.titleIconSize); this.canvas.setCoordinateSpaceWidth(size); this.canvas.setCoordinateSpaceHeight(size + Style.toPixelRatio(1)); buffer.setCoordinateSpaceWidth(size); buffer.setCoordinateSpaceHeight(size); if (this.active) { img = this.imgActive; } else { img = this.imgNormal; } // We need to draw the icon itself in a separate buffer, and only // after apply the shadow. // The reason is that in order to draw the icon using the color we // want, we need to use composite operations, and this is not // compatible with the shadow effect we want. ctx = buffer.getContext2d(); if (this.over) { ctx.setFillStyle("#fff"); } else { ctx.setFillStyle("#ddd"); } ctx.fillRect(0, 0, size, size); ctx.setGlobalCompositeOperation(Composite.DESTINATION_ATOP); ctx.drawImage(ImageElement.as(img.getElement()), 0, 0, size, size); ctx.restore(); ctx = this.canvas.getContext2d(); ctx.setShadowBlur(0.0); ctx.setShadowColor("#333"); ctx.setShadowOffsetY(Style.toPixelRatio(1)); ctx.drawImage(buffer.getCanvasElement(), 0, 0, size, size); }
From source file:com.lizardtech.djvu.DjVuPage.java
License:Open Source License
private GPixmap decodeJPEG(CachedInputStream iff) throws IOException { final GPixmap result = new GPixmap(); final Image image = new Image(); final ImageElement imageElement = image.getElement().cast(); imageElement.getStyle().setProperty("visibility", "hidden"); Event.setEventListener(imageElement, new EventListener() { @Override/*from w ww .j av a2 s . com*/ public void onBrowserEvent(Event event) { if (Event.ONLOAD == event.getTypeInt()) { final int w = imageElement.getWidth(), h = imageElement.getHeight(); final Canvas canvas = Canvas.createIfSupported(); canvas.setWidth(w + "px"); canvas.setCoordinateSpaceWidth(w); canvas.setHeight(h + "px"); canvas.setCoordinateSpaceHeight(h); canvas.getContext2d().drawImage(imageElement, 0, 0); result.init(h, w, null); result.setImageData(canvas.getContext2d().getImageData(0, 0, w, h)); } } }); StringBuilder data = new StringBuilder(); int b; while ((b = iff.read()) != -1) { data.append((char) b); } String dataURL = "data:image/jpeg;base64," + btoa(data.toString()); image.setUrl(dataURL); return result; }