List of usage examples for com.google.gwt.canvas.dom.client Context2d getImageData
public final native ImageData getImageData(double sx, double sy, double sw, double sh) ;
From source file:playn.html.HtmlCanvasImage.java
License:Apache License
@Override public void setRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { Context2d ctx = canvas.canvas().getContext2d(); ImageData imageData = ctx.getImageData(startX, startY, width, height); CanvasPixelArray pixelData = imageData.getData(); int i = 0;//from ww w. ja va2s .com int dst = offset; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgba = rgbArray[dst + x]; pixelData.set(i++, (rgba >> 16) & 255); pixelData.set(i++, (rgba >> 8) & 255); pixelData.set(i++, (rgba) & 255); pixelData.set(i++, (rgba >> 24) & 255); } dst += scanSize; } }
From source file:playn.html.HtmlImage.java
License:Apache License
@Override public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { Asserts.checkState(isReady(), "Cannot getRgb() a non-ready image"); if (canvas == null) { canvas = img.getOwnerDocument().createCanvasElement(); canvas.setHeight(img.getHeight()); canvas.setWidth(img.getWidth()); canvas.getContext2d().drawImage(img, 0, 0); // img.getOwnerDocument().getBody().appendChild(canvas); }/* w w w .j av a 2 s . c om*/ Context2d ctx = canvas.getContext2d(); ImageData imageData = ctx.getImageData(startX, startY, width, height); CanvasPixelArray pixelData = imageData.getData(); int i = 0; int dst = offset; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int r = pixelData.get(i++); int g = pixelData.get(i++); int b = pixelData.get(i++); int a = pixelData.get(i++); rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b; } dst += scanSize; } }
From source file:thothbot.parallax.core.client.renderers.RaytracingRenderer.java
License:Open Source License
public RaytracingRenderer(int width, int height) { canvas = Canvas.createIfSupported(); canvas.ensureDebugId("canvas2d"); setSize(width, height);// ww w. j ava 2 s . c o m context = canvas.getContext2d(); context.setFillStyle("#FFFFFF"); canvasBlock = Canvas.createIfSupported(); canvasBlock.setCoordinateSpaceWidth(blockSize); canvasBlock.setCoordinateSpaceHeight(blockSize); RootPanel.get().add(canvasBlock, -10000, 0); Context2d contextBlock = canvasBlock.getContext2d(); imagedata = contextBlock.getImageData(0, 0, blockSize, blockSize); }