List of usage examples for com.google.gwt.canvas.dom.client Context2d createImageData
public final native ImageData createImageData(int w, int h) ;
From source file:net.npe.gwt.canvas.CanvasCreator.java
License:MIT License
public static Canvas createImageCanvas(int[] pixels, int width, int height) { Canvas canvas = Canvas.createIfSupported(); if (canvas == null) return null; 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); }//from w ww . j av a 2 s. com context.putImageData(data, 0, 0); return canvas; }
From source file:net.npe.image.util.gwt.GwtImageReader.java
License:MIT License
public static Canvas createCanvas(int[] pixels, int width, int height) { Canvas canvas = Canvas.createIfSupported(); if (canvas == null) return null; 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); }/* w w w. j a v a 2 s. c om*/ context.putImageData(data, 0, 0); return canvas; }