com.google.gwt.canvas.dom.client.ImageData Java Examples
The following examples show how to use
com.google.gwt.canvas.dom.client.ImageData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TexturedCube.java From TGAReader with MIT License | 6 votes |
Canvas createImageCanvas(int [] pixels, int width, int height) { Canvas canvas = Canvas.createIfSupported(); canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); Context2d context = canvas.getContext2d(); ImageData data = context.createImageData(width, height); CanvasPixelArray array = data.getData(); for(int i=0; i<width*height; i++) { array.set(4*i+0, pixels[i] & 0xFF); array.set(4*i+1, (pixels[i] >> 8) & 0xFF); array.set(4*i+2, (pixels[i] >> 16) & 0xFF); array.set(4*i+3, (pixels[i] >> 24) & 0xFF); } context.putImageData(data, 0, 0); return canvas; }
Example #2
Source File: ImageCanvasTest.java From TGAReader with MIT License | 6 votes |
private Canvas createImageCanvas(int [] pixels, int width, int height) { Canvas canvas = Canvas.createIfSupported(); canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); Context2d context = canvas.getContext2d(); ImageData data = context.createImageData(width, height); CanvasPixelArray array = data.getData(); for(int i=0; i<width*height; i++) { // ABGR array.set(4*i+0, pixels[i] & 0xFF); array.set(4*i+1, (pixels[i] >> 8) & 0xFF); array.set(4*i+2, (pixels[i] >> 16) & 0xFF); array.set(4*i+3, (pixels[i] >> 24) & 0xFF); } context.putImageData(data, 0, 0); canvas.getElement().getStyle().setMargin(4, Unit.PX); return canvas; }
Example #3
Source File: TextMetricsCalculator.java From jetpad-projectional-open-source with Apache License 2.0 | 5 votes |
private static int measureHeight(Font font, String text) { Canvas canvas = canvas(); Context2d ctx = canvas.getContext2d(); ctx.setFont(getFontString(font)); ctx.setFillStyle("rgb(255, 0, 0)"); int width = (int) ctx.measureText(text).getWidth(); int canvasHeight = font.getSize() * 2; canvas.setHeight(canvasHeight + "px"); canvas.setHeight(font.getSize() * 2 + "px"); canvas.setWidth(width + "px"); ctx.fillText(text, 0, font.getSize()); ImageData data = ctx.getImageData(0, 0, width, canvasHeight); int firstY = canvasHeight - 1; int lastY = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < canvasHeight; y++) { int red = data.getRedAt(x, y); if (red != 0) { if (firstY > y) { firstY = y; } if (lastY < y) { lastY = y; } } } } return lastY - firstY; }