Example usage for com.google.gwt.canvas.dom.client Context2d putImageData

List of usage examples for com.google.gwt.canvas.dom.client Context2d putImageData

Introduction

In this page you can find the example usage for com.google.gwt.canvas.dom.client Context2d putImageData.

Prototype

public final native void putImageData(ImageData imagedata, double x, double y) ;

Source Link

Document

Draws the given image data at the given screen position.

Usage

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 {/*  w w  w .  j a v a  2s  .com*/
        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: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);/*from   w  ww . j  a v a  2 s. c o  m*/

    canvasTmp.addStyleName("test2");
}

From source file:com.google.gwt.sample.userwatcher.client.ImageUtils.java

/**
 * for debugging/*from www.  j  a v  a 2  s  .  co  m*/
 * 
 * @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

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.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();
    }/*from  w  ww. j av  a  2s.c  o  m*/

    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.lizardtech.djvu.GBitmap.java

License:Open Source License

@Override
public void putData(Context2d target) {
    target.putImageData(imageData, -border, 0);
}

From source file:com.lizardtech.djvu.GPixmap.java

License:Open Source License

@Override
public void putData(Context2d target) {
    target.putImageData(imageData, 0, 0);
}

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  .c o m*/
    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);
    }//from  w  w w . j a v  a2s  . c  o  m
    context.putImageData(data, 0, 0);

    return canvas;

}

From source file:org.catrobat.html5player.client.Scene.java

License:Open Source License

/**
 *
 * @param imageElement/*from ww  w  . ja  va 2 s  .co  m*/
 * @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;
}