Example usage for com.google.gwt.dom.client ImageElement getWidth

List of usage examples for com.google.gwt.dom.client ImageElement getWidth

Introduction

In this page you can find the example usage for com.google.gwt.dom.client ImageElement getWidth.

Prototype

public int getWidth() 

Source Link

Document

The width of the image in pixels.

Usage

From source file:com.ait.lienzo.client.core.util.ScratchCanvas.java

License:Open Source License

public static final String toDataURL(ImageElement element, DataURLType mimetype) {
    if (null == mimetype) {
        mimetype = DataURLType.PNG;//from   w  w w.ja va  2s. c o m
    }
    ScratchCanvas canvas = new ScratchCanvas(element.getWidth(), element.getHeight());

    canvas.getContext().drawImage(element, 0, 0, element.getWidth(), element.getHeight());

    return canvas.toDataURL(mimetype);
}

From source file:com.ait.lienzo.client.core.util.ScratchPad.java

License:Open Source License

public static final String toDataURL(final ImageElement element, DataURLType mimetype, final double quality) {
    if (null == mimetype) {
        mimetype = DataURLType.PNG;//  w w  w .j  a v  a2 s  .  c  o m
    }
    ScratchPad canvas = new ScratchPad(element.getWidth(), element.getHeight());

    canvas.getContext().drawImage(element, 0, 0, element.getWidth(), element.getHeight());

    return canvas.toDataURL(mimetype, quality);
}

From source file:com.ait.lienzo.client.core.util.ScratchPad.java

License:Open Source License

public static final String toDataURL(final ImageElement element) {
    final ScratchPad canvas = new ScratchPad(element.getWidth(), element.getHeight());

    canvas.getContext().drawImage(element, 0, 0);

    return canvas.toDataURL();
}

From source file:com.badlogic.gdx.graphics.Pixmap.java

License:Apache License

public Pixmap(FileHandle file) {
    GwtFileHandle gwtFile = (GwtFileHandle) file;
    ImageElement img = gwtFile.preloader.images.get(file.path());
    if (img == null)
        throw new GdxRuntimeException("Couldn't load image '" + file.path() + "', file does not exist");
    create(img.getWidth(), img.getHeight(), Format.RGBA8888);
    context.setGlobalCompositeOperation(Composite.COPY);
    context.drawImage(img, 0, 0);/*from  ww  w  . j a  v  a2  s .  c  o m*/
    context.setGlobalCompositeOperation(getComposite());
}

From source file:com.badlogic.gdx.graphics.Pixmap.java

License:Apache License

public Pixmap(ImageElement img) {
    create(img.getWidth(), img.getHeight(), Format.RGBA8888);
    context.drawImage(img, 0, 0);
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private void findImages() {
    mImages = new ArrayList<MarkupParser.Image>();

    NodeList<Element> allImages = mRoot.getElementsByTagName("IMG");
    for (int i = 0; i < allImages.getLength(); i++) {
        ImageElement imgElem = ImageElement.as(allImages.getItem(i));

        // As long as the image has a caption, it's relevant regardless of size;
        // otherwise, it's relevant if its size is good.
        String caption = getCaption(imgElem);
        if ((caption != null && !caption.isEmpty()) || isImageRelevantBySize(imgElem)) {
            // Add relevant image to list.
            MarkupParser.Image image = new MarkupParser.Image();
            image.url = imgElem.getSrc();
            image.caption = caption;/*  w w  w  . ja  v a  2  s . com*/
            image.width = imgElem.getWidth();
            image.height = imgElem.getHeight();
            mImages.add(image);
        }
    }
}

From source file:com.dom_distiller.client.IEReadingViewParser.java

License:Open Source License

private static boolean isImageRelevantBySize(ImageElement image) {
    // Relevant image size: width >= 400 and aspect ratio between 1.3 and 3.0 inclusively.
    int width = image.getWidth();
    if (width < 400)
        return false;
    double aspectRatio = (double) width / (double) image.getHeight();
    return aspectRatio >= 1.3 && aspectRatio <= 3.0;
}

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

/**
 * image - an ImageElement object/*from   w ww  .  java2 s .  c  o  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.googlecode.gwtquake.client.GwtWebGLRenderer.java

License:Open Source License

public void setPicDataHighLevel(Image image, ImageElement img) {
    image.has_alpha = true;//from   www. ja v a  2s  .c  om
    image.complete = true;
    image.height = img.getHeight();
    image.width = img.getWidth();

    boolean mipMap = image.type != com.googlecode.gwtquake.shared.common.QuakeImage.it_pic
            && image.type != com.googlecode.gwtquake.shared.common.QuakeImage.it_sky;

    Images.GL_Bind(image.texnum);

    int p2w = 1 << ((int) Math.ceil(Math.log(image.width) / Math.log(2)));
    int p2h = 1 << ((int) Math.ceil(Math.log(image.height) / Math.log(2)));

    if (mipMap) {
        p2w = p2h = Math.max(p2w, p2h);
    }

    image.upload_width = p2w;
    image.upload_height = p2h;

    int level = 0;
    do {
        canvas1.setWidth(p2w);
        canvas1.setHeight(p2h);

        canvas1.getContext2D().clearRect(0, 0, p2w, p2h);
        canvas1.getContext2D().drawImage(img, 0, 0, p2w, p2h);

        webGL.glTexImage2d(TEXTURE_2D, level++, RGBA, RGBA, UNSIGNED_BYTE, canvas1);

        p2w = p2w / 2;
        p2h = p2h / 2;
    } while (mipMap && p2w > 0);

    GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MIN_FILTER, mipMap ? LINEAR_MIPMAP_NEAREST : LINEAR);
    GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
}

From source file:com.googlecode.gwtquake.client.GwtWebGLRenderer.java

License:Open Source License

public void __setPicDataHighLevel(Image image, ImageElement img) {
    image.has_alpha = true;/*w ww  .j  a va  2  s.  c o m*/
    image.complete = true;
    image.height = img.getHeight();
    image.width = img.getWidth();
    image.upload_height = image.height;
    image.upload_width = image.width;
    Images.GL_Bind(image.texnum);
    webGL.glTexImage2d(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, img);
    GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
    GlState.gl.glTexParameterf(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
}