Java 类com.google.gwt.dom.client.ImageElement 实例源码

项目:gwt-promptly    文件:PromptlyPanel.java   
public final ItemHandle appendEmbeddedImage(
     HAlignment imageAlignment,
     String embeddedImageText,
     String embeddedImageStyle,
     String description
) {
   FlowPanel outer = new FlowPanel(DivElement.TAG);
   String imageAlignment1 = "text-align:center;";
   if (imageAlignment == HAlignment.LEFT) {
      imageAlignment1 = "text-align:left;";
   } else if (imageAlignment == HAlignment.RIGHT) {
      imageAlignment1 = "text-align:right;";
   }
   outer.getElement().setAttribute("style", "display:block;" + imageAlignment1);
   FlowPanel inner = new FlowPanel(ImageElement.TAG);
   inner.getElement().setAttribute("alt",   description);
   inner.getElement().setAttribute("src",   embeddedImageText);
   inner.getElement().setAttribute("style", embeddedImageStyle);
   outer.add(inner);
   appendAndScrollOrFocusAsAppropriate(outer);
   return new ItemHandle(this, outer);
}
项目:gwt-pwa-archetype    文件:View1.java   
public View1() {
   initWidget(viewUi.createAndBindUi(this));

   // Image renderer
   grid.ready(o -> {
     Column column = grid.getColumns().get(0).cast();
     column.setRenderer(row -> {
         Row r = (Row)row;
         Element e = r.getElement().cast();
         ImageElement img = e.getFirstChild().cast();
         if (img == null) {
           img = Document.get().createImageElement();
           e.appendChild(img);
         }
         img.setSrc(r.getData().toString());
         return 0;
     });

     // Send the request
     Polymer.Base.async(o2 -> ajax.generateRequest(), 1000);
     return 0;
   });
}
项目:playn    文件:WebGLDemo.java   
private WebGLTexture createTexture(String url) {
  // Create the texture object.
  final WebGLTexture tex = gl.createTexture();

  // Load the image.
  final ImageElement img = createImage();
  img.setSrc(url);
  hookOnLoad(img, new EventHandler() {
    @Override
    public void onEvent(NativeEvent e) {
      // Load image data into the texture object once it's loaded.
      gl.bindTexture(TEXTURE_2D, tex);
      gl.texImage2D(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, img);
      gl.texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
      gl.texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
      gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
      gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
      gl.bindTexture(TEXTURE_2D, null);
    }
  });

  return tex;
}
项目:forplay    文件:HtmlImageLayerGL.java   
@Override
void paint(WebGLRenderingContext gl, Transform parentTransform, float parentAlpha) {
  if (!visible()) return;

  // TODO(jgw): Assert exclusive source-rect vs. repeat.

  WebGLTexture tex = img.ensureTexture(gfx, repeatX, repeatY);
  if (tex != null) {
    ImageElement elem = img.img;

    Transform xform = localTransform(parentTransform);
    float childAlpha = parentAlpha * alpha;

    float width = widthSet ? this.width : elem.getWidth();
    float height = heightSet ? this.height : elem.getHeight();

    if (sourceRectSet) {
      gfx.drawTexture(tex, img.width(), img.height(), xform, 0, 0, width, height, sx, sy, sw, sh,
          childAlpha);
    } else {
      gfx.drawTexture(tex, img.width(), img.height(), xform, width, height, repeatX, repeatY,
          childAlpha);
    }
  }
}
项目:forplay    文件:WebGLDemo.java   
private WebGLTexture createTexture(String url) {
  // Create the texture object.
  final WebGLTexture tex = gl.createTexture();

  // Load the image.
  final ImageElement img = createImage();
  img.setSrc(url);
  hookOnLoad(img, new EventHandler() {
    @Override
    public void onEvent(NativeEvent e) {
      // Load image data into the texture object once it's loaded.
      gl.bindTexture(TEXTURE_2D, tex);
      gl.texImage2D(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, img);
      gl.texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
      gl.texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
      gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
      gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
      gl.bindTexture(TEXTURE_2D, null);
    }
  });

  return tex;
}
项目:che    文件:AbstractPresentationRenderer.java   
/** {@inheritDoc} */
@Override
public Element getIconContainer(SVGResource icon) {
  if (icon != null) {
    OMSVGSVGElement svg = icon.getSvg();
    svg.addClassNameBaseVal(treeStyles.styles().iconContainer());
    svg.setWidth(Style.Unit.PX, 16);
    svg.setHeight(Style.Unit.PX, 16);
    return svg.getElement();
  }

  ImageElement emptyIcon = Document.get().createImageElement();
  emptyIcon.setSrc(TreeView.blankImageUrl);
  emptyIcon.setClassName(treeStyles.styles().iconContainer());
  return emptyIcon;
}
项目:r01fb    文件:TagList.java   
private static LIElement _createBaseTagElement() {
    //      <ul class='tags'>
    //          <li><span><img />Tag1</span></li>
    //          <li><span><img />Tag1</span></li>
    //          ...
    //      </ul>
    LIElement containerLIEl = DOM.createElement("li").cast();
    SpanElement spanEl = DOM.createSpan().cast();
    ImageElement imgEl = DOM.createImg().cast();

    // assemble the structure
    spanEl.appendChild(imgEl);
    spanEl.appendChild(Document.get().createTextNode(""));
    containerLIEl.appendChild(spanEl);
    return containerLIEl;
}
项目:r01fb    文件:TagList.java   
@Override
    @SuppressWarnings("fallthrough")
    public void onBrowserEvent(final Event event) {
        super.onBrowserEvent(event);

        int eventType = DOM.eventGetType(event);
        Element eventTargetEl = DOM.eventGetTarget(event);

//      GWT.log("_____" + eventTargetEl.getNodeName() + ": " + event.getType());

        switch (eventType) {
        case Event.ONCLICK: {
            if (ImageElement.is(eventTargetEl)) {
                LIElement tagLIElement = _findTagLIElementContaining(eventTargetEl);
                T tag = _tagForElement(tagLIElement);
                this.removeTag(tag);
            }
            break;
        }
        }
    }
项目:dom-distiller    文件:DomUtil.java   
private static void makeSrcSetAbsolute(Element ie) {
    String srcset = ie.getAttribute("srcset");
    if (srcset.isEmpty()) {
        ie.removeAttribute("srcset");
        return;
    }

    ImageElement holder = Document.get().createImageElement();
    String[] sizes = StringUtil.jsSplit(srcset, ",");
    for(int i = 0; i < sizes.length; i++) {
        String size = StringUtil.jsTrim(sizes[i]);
        if (size.isEmpty()) continue;
        String[] comp = size.split(" ");
        holder.setSrc(comp[0]);
        comp[0] = holder.getSrc();
        sizes[i] = StringUtil.join(comp, " ");
    }
    ie.setAttribute("srcset", StringUtil.join(sizes, ", "));
}
项目:dom-distiller    文件:DomUtil.java   
/**
 * Only keep some attributes for image elements.
 * @param imgElement The image element to strip in-place.
 */
public static void stripImageElement(ImageElement imgElement) {
    JsArray<Node> attrs = getAttributes(imgElement);
    for (int i = 0; i < attrs.length(); ) {
        String name = attrs.get(i).getNodeName();
        if (!"src".equals(name) &&
            !"alt".equals(name) &&
            !"srcset".equals(name) &&
            !"dir".equals(name) &&
            !"width".equals(name) &&
            !"height".equals(name) &&
            !"title".equals(name)) {
            imgElement.removeAttribute(name);
        } else {
            i++;
        }
    }
}
项目:dom-distiller    文件:WebTable.java   
/**
 * Get the list of source URLs of this image.
 * It's more efficient to call after generateOutput().
 * @return Source URLs or an empty List.
 */
public List<String> getImageUrlList() {
    if (cloned == null) {
        cloneAndProcessNode();
    }
    List<String> imgUrls = new ArrayList<>();
    NodeList<Element> imgs = DomUtil.querySelectorAll(cloned, "IMG, SOURCE");
    for (int i = 0; i < imgs.getLength(); i++) {
        ImageElement ie = (ImageElement) imgs.getItem(i);
        if (!ie.getSrc().isEmpty()) {
            imgUrls.add(ie.getSrc());
        }
        imgUrls.addAll(DomUtil.getAllSrcSetUrls(ie));
    }
    return imgUrls;
}
项目:dom-distiller    文件:IEReadingViewParser.java   
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;
            image.width = imgElem.getWidth();
            image.height = imgElem.getHeight();
            mImages.add(image);
        }
    }
}
项目:dom-distiller    文件:IEReadingViewParser.java   
private static String getCaption(ImageElement image) {
    // If |image| is a child of <figure>, then get the <figcaption> elements.
    Element parent = image.getParentElement();
    if (!parent.hasTagName("FIGURE")) return "";
    NodeList<Element> captions = parent.getElementsByTagName("FIGCAPTION");
    int numCaptions = captions.getLength();
    String caption = "";
    if (numCaptions > 0 && numCaptions <= 2) {
        // Use javascript innerText (instead of javascript textContent) to get only visible
        // captions.
        for (int i = 0; i < numCaptions && caption.isEmpty(); i++) {
            caption = DomUtil.getInnerText(captions.getItem(i));
        }
    }
    return caption;
}
项目:dom-distiller    文件:ImageExtractor.java   
private void extractImageAttributes(ImageElement imageElement) {
    // This will get the absolute URL of the image and
    // the displayed image dimension.
    // Try to get lazily-loaded images before falling back to get the src attribute.
    for (String attr : LAZY_IMAGE_ATTRIBUTES) {
        imgSrc = imageElement.getAttribute(attr);
        if (!imgSrc.isEmpty())
            break;
    }
    if (!imgSrc.isEmpty()) {
        // We cannot trust the dimension if the image is not loaded yet.
        // In some cases there are 1x1 placeholder images.
        width = 0;
        height = 0;
    } else {
        imgSrc = imageElement.getSrc();
        // As an ImageElement is manipulated here, it is possible
        // to get the real dimensions.
        width = imageElement.getWidth();
        height = imageElement.getHeight();
    }
    if (LogUtil.isLoggable(LogUtil.DEBUG_LEVEL_VISIBILITY_INFO)) {
        LogUtil.logToConsole("Extracted WebImage: " + imgSrc);
    }
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testUncaptionedDominantImage() {
    Element root = TestUtil.createDiv(0);
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/dominant_without_caption.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(600);
    img.setHeight(400);
    root.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(1, images.length);
    MarkupParser.Image image = images[0];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals("", image.caption);
    assertEquals(600, image.width);
    assertEquals(400, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testCaptionedDominantImageWithSmallestAR() {
    Element root = TestUtil.createDiv(0);
    String expectedCaption = "Captioned Dominant Image with Smallest AR";
    Element figure = createFigureWithCaption(expectedCaption);
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/captioned_smallest_dominant.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(400);
    img.setHeight(307);

    root.appendChild(figure);
    figure.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(1, images.length);
    MarkupParser.Image image = images[0];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals(expectedCaption, image.caption);
    assertEquals(400, image.width);
    assertEquals(307, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testCaptionedDominantImageWithBiggestAR() {
    Element root = TestUtil.createDiv(0);
    String expectedCaption = "Captioned Dominant Image with Biggest AR";
    Element figure = createFigureWithCaption(expectedCaption);
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/captioned_biggest_dominant.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(400);
    img.setHeight(134);

    root.appendChild(figure);
    figure.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(1, images.length);
    MarkupParser.Image image = images[0];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals(expectedCaption, image.caption);
    assertEquals(400, image.width);
    assertEquals(134, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testCaptionedDominantImageWithInvalidSize() {
    Element root = TestUtil.createDiv(0);
    String expectedCaption = "Captioned Dominant Image with Invalid Size";
    Element figure = createFigureWithCaption(expectedCaption);
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/captioned_dominant_with_wrong_dimensions.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(100);
    img.setHeight(100);

    root.appendChild(figure);
    figure.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(1, images.length);
    MarkupParser.Image image = images[0];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals(expectedCaption, image.caption);
    assertEquals(100, image.width);
    assertEquals(100, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testUncaptionedInlineImageWithSmallestAR() {
    Element root = TestUtil.createDiv(0);
    Element figure = createDefaultDominantFigure();
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/inline_without_caption.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(400);
    img.setHeight(307);

    root.appendChild(figure);
    root.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(2, images.length);
    MarkupParser.Image image = images[1];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals("", image.caption);
    assertEquals(400, image.width);
    assertEquals(307, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testUncaptionedInlineImageWithBiggestAR() {
    Element root = TestUtil.createDiv(0);
    Element figure = createDefaultDominantFigure();
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/inline_without_caption.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(400);
    img.setHeight(134);

    root.appendChild(figure);
    root.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(2, images.length);
    MarkupParser.Image image = images[1];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals("", image.caption);
    assertEquals(400, image.width);
    assertEquals(134, image.height);
}
项目:dom-distiller    文件:IEReadingViewParserTest.java   
public void testCaptionedInlineImageWithInvalidSize() {
    Element root = TestUtil.createDiv(0);
    Element dominant = createDefaultDominantFigure();
    String expectedCaption = "Captioned Inline Image with Smallest AR";
    Element figure = createFigureWithCaption(expectedCaption);
    ImageElement img = TestUtil.createImage();
    String expectedUrl = "http://example.com/captioned_smallest_inline.jpeg";
    img.setSrc(expectedUrl);
    img.setWidth(400);
    img.setHeight(400);

    root.appendChild(dominant);
    root.appendChild(figure);
    figure.appendChild(img);

    IEReadingViewParser parser = new IEReadingViewParser(root);
    MarkupParser.Image[] images = parser.getImages();
    assertEquals(2, images.length);
    MarkupParser.Image image = images[1];
    assertEquals(expectedUrl, image.url);
    assertEquals("", image.secureUrl);
    assertEquals("", image.type);
    assertEquals(expectedCaption, image.caption);
    assertEquals(400, image.width);
    assertEquals(400, image.height);
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
private void extractLazilyLoadedImage(String attr) {
    ImageElement image = TestUtil.createImage();
    image.setAttribute(attr, "image.png");
    mBody.appendChild(image);

    mHead.setInnerHTML("<base href=\"http://example.com/\">");

    EmbedExtractor extractor = new ImageExtractor();
    WebImage result = (WebImage) extractor.extract(image);
    assertNotNull(result);
    assertEquals("<img src=\"http://example.com/image.png\">", result.generateOutput(false));

    List<String> expected = new ArrayList<String>();
    expected.add("http://example.com/image.png");
    assertEquals(expected, result.getUrlList());
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
private void extractLazilyLoadedFigure(String attr) {
    ImageElement image = TestUtil.createImage();
    image.setAttribute(attr, "image.png");
    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);

    mBody.appendChild(figure);

    mHead.setInnerHTML("<base href=\"http://example.com/\">");

    EmbedExtractor extractor = new ImageExtractor();
    WebFigure result = (WebFigure) extractor.extract(figure);
    assertNotNull(result);
    assertEquals("<figure><img src=\"http://example.com/image.png\"></figure>",
            result.generateOutput(false));

    List<String> expected = new ArrayList<String>();
    expected.add("http://example.com/image.png");
    assertEquals(expected, result.getUrlList());
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
public void testFigureWithoutCaption() {
    ImageElement image = TestUtil.createImage();
    image.setSrc("http://wwww.example.com/image.jpeg");
    image.setAttribute("width", "100");
    image.setAttribute("height", "100");
    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);
    mBody.appendChild(figure);

    EmbedExtractor extractor = new ImageExtractor();
    WebImage result = (WebImage) extractor.extract(figure);
    String got = result.generateOutput(false);
    String expected =
        "<figure>" +
            "<img src=\"http://wwww.example.com/image.jpeg\"" +
                " width=\"100\" height=\"100\">" +
        "</figure>";
    assertNotNull(result);
    assertEquals(100, result.getHeight());
    assertEquals(100, result.getWidth());
    assertEquals(expected, got);
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
public void testFigureWithoutCaptionWithNoscript() {
    ImageElement image = TestUtil.createImage();
    image.setSrc("http://wwww.example.com/image.jpeg");
    image.setAttribute("width", "100");
    image.setAttribute("height", "100");
    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);
    Element noscript = Document.get().createElement("NOSCRIPT");
    noscript.setInnerHTML("<span>text</span>");
    figure.appendChild(noscript);
    mBody.appendChild(figure);

    EmbedExtractor extractor = new ImageExtractor();
    WebImage result = (WebImage) extractor.extract(figure);
    String got = result.generateOutput(false);
    String expected =
        "<figure>" +
            "<img src=\"http://wwww.example.com/image.jpeg\"" +
                " width=\"100\" height=\"100\">" +
        "</figure>";
    assertNotNull(result);
    assertEquals(100, result.getHeight());
    assertEquals(100, result.getWidth());
    assertEquals(expected, got);
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
public void testFigureCaptionTextOnly() {
    ImageElement image = TestUtil.createImage();
    image.setSrc("http://wwww.example.com/image.jpeg");
    image.setAttribute("width", "100");
    image.setAttribute("height", "100");

    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);
    Element figcaption = Document.get().createElement("FIGCAPTION");
    figcaption.setInnerHTML("This is a caption");
    figure.appendChild(figcaption);
    mBody.appendChild(figure);

    EmbedExtractor extractor = new ImageExtractor();
    WebElement result = extractor.extract(figure);
    assertEquals("This is a caption", result.generateOutput(true));
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
public void testFigureWithCaptionWithoutAnchor() {
    ImageElement image = TestUtil.createImage();
    image.setSrc("http://wwww.example.com/image.jpeg");
    image.setAttribute("width", "100");
    image.setAttribute("height", "100");
    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);
    Element figcaption = Document.get().createElement("FIGCAPTION");
    figcaption.setInnerHTML("<div><span>This is a caption</span><a></a></div>");
    figure.appendChild(figcaption);
    mBody.appendChild(figure);

    EmbedExtractor extractor = new ImageExtractor();
    WebImage result = (WebImage) extractor.extract(figure);
    String expected =
        "<figure>" +
            "<img src=\"http://wwww.example.com/image.jpeg\"" +
                " width=\"100\" height=\"100\">" +
            "<figcaption>This is a caption</figcaption>" +
        "</figure>";
    assertNotNull(result);
    assertEquals(100, result.getHeight());
    assertEquals(100, result.getWidth());
    assertEquals(expected, TestUtil.removeAllDirAttributes(
            result.generateOutput(false)));
}
项目:dom-distiller    文件:EmbedExtractorTest.java   
public void testDivCaption() {
    ImageElement image = TestUtil.createImage();
    image.setSrc("http://wwww.example.com/image.jpeg");
    image.setAttribute("width", "100");
    image.setAttribute("height", "100");

    Element figure = Document.get().createElement("FIGURE");
    figure.appendChild(image);
    Element div = Document.get().createElement("DIV");
    div.setInnerHTML("This is a caption");
    figure.appendChild(div);
    mBody.appendChild(figure);
    String expected =
        "<figure>" +
            "<img src=\"http://wwww.example.com/image.jpeg\"" +
                " width=\"100\" height=\"100\">" +
            "<figcaption>\nThis is a caption</figcaption>" +
        "</figure>";
    EmbedExtractor extractor = new ImageExtractor();
    WebElement result = extractor.extract(figure);
    assertEquals(expected, TestUtil.removeAllDirAttributes(
            result.generateOutput(false)));
}
项目:djvu-html5    文件:DataStore.java   
private CanvasElement prepareMissingTileImage() {
    int tileSize = DjvuContext.getTileSize();
    CanvasElement canvas = createImage(tileSize, tileSize);
    Context2d context2d = canvas.getContext2d();
    context2d.setFillStyle("white");
    context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
    Image image = new Image();
    final ImageElement imageElement = image.getElement().cast();
    imageElement.getStyle().setProperty("visibility", "hidden");
    Event.setEventListener(imageElement, event -> {
        if (Event.ONLOAD == event.getTypeInt()) {
            missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
            RootPanel.get().getElement().removeChild(imageElement);
        }
    });
    RootPanel.get().getElement().appendChild(imageElement);
    image.setUrl(getBlankImageUrl());
    return canvas;
}
项目:GWTModelWeight    文件:UvPackToolPanel.java   
private void packUVImage(ImageElement element,int split,int x,int y){

    if(element==null){
        return;
    }
    int canvasSize=textureCanvas.getCoordinateSpaceWidth();
    int unitSize=canvasSize/split;

    if(resizeCanvas==null){
        resizeCanvas=Canvas.createIfSupported();
    }
    Canvas resized=CanvasResizer.on(resizeCanvas).image(element).width(unitSize).downscale(false).toCanvas();//downscale transparent problem

    textureCanvas.getContext2d().drawImage(resized.getCanvasElement(), unitSize*x, unitSize*y);
}
项目:platypus-js    文件:ModelColumn.java   
protected static void bindIconCallback(final PublishedCell aCell, final String aTargetElementId) {
    aCell.setIconCallback(new Runnable() {

        @Override
        public void run() {
            Element identifiedTextSection = Document.get().getElementById(aTargetElementId);
            if (identifiedTextSection != null) {
                ImageElement iconSection = (ImageElement) identifiedTextSection.getPreviousSiblingElement();
                if (iconSection != null) {
                    if (aCell.getIcon() != null) {
                        iconSection.setSrc(aCell.getIcon().getSafeUri().asString());
                    } else {
                        iconSection.setSrc(null);
                    }
                }
            }
        }

    });
}
项目:gwthtml5apps    文件:TransparentIt.java   
private void updateBgImage(ImageElement bgImage){
    canvas.removeStyleName("newbg");
    if(injectedBgCss!=null){
        injectedBgCss.removeFromParent();
    }

    if(bgImage!=null){
        int w=(int) (bgImage.getWidth()*currentScale);
        int h=(int) (bgImage.getHeight()*currentScale);
        String css=".newbg{"+"background-image: url(\""+bgImage.getSrc()+"\");background-size:"+w+"px "+h+"px;"+"}";
        injectedBgCss = StyleInjector.injectStylesheet(css);

        canvas.addStyleName("newbg");

        updateCanvas(false);
    }
}
项目:gwthtml5apps    文件:TransparentIt.java   
protected void drawImage(ImageElement img) {
    try{

    //need for some transparent image
    canvas.getContext2d().clearRect(0, 0, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());

    //canvas.getContext2d().save();

    //no need to flip
    //canvas.getContext2d().translate(originImage.getCoordinateSpaceWidth(), 0); //flip horizontal
    //canvas.getContext2d().scale(-1, 1);
    //canvas.getContext2d().transform(-1, 0, 0, 1, 0, 0);
    canvas.getContext2d().drawImage(selection.getImageElement(), 0, 0);
    //canvas.getContext2d().restore();

    }catch(Exception e){
        LogUtils.log("error:"+e.getMessage());
    }

    //canvas.getContext2d().setFillStyle("rgba(0,0,0,0)");
    //canvas.getContext2d().setGlobalCompositeOperation("destination-out");
    //canvas.getContext2d().fillRect(100, 100, 100, 100);
}
项目:gwthtml5apps    文件:TransparentIt.java   
@Override
public void undo() {

    ImageElementLoader loader=new ImageElementLoader();
    loader.load(beforeUri, new ImageElementListener() {
        @Override
        public void onLoad(ImageElement element) {
            canvas.getContext2d().save();
            canvas.getContext2d().setGlobalCompositeOperation(Composite.COPY);
            canvas.getContext2d().drawImage(element,0,0);
            canvas.getContext2d().restore();

            updateCurrentSelectionDataUrl(beforeUri);
        }

        @Override
        public void onError(String url, ErrorEvent event) {
            Window.alert(event.toDebugString());
        }
    });

}
项目:gwthtml5apps    文件:TransparentIt.java   
@Override
public void redo() {
    ImageElementLoader loader=new ImageElementLoader();
    loader.load(afterUri, new ImageElementListener() {
        @Override
        public void onLoad(ImageElement element) {
            canvas.getContext2d().save();
            canvas.getContext2d().setGlobalCompositeOperation(Composite.COPY);
            canvas.getContext2d().drawImage(element,0,0);
            canvas.getContext2d().restore();

            updateCurrentSelectionDataUrl(afterUri);
        }

        @Override
        public void onError(String url, ErrorEvent event) {
            Window.alert(event.toDebugString());
        }
    });


}
项目:gwthtml5apps    文件:Inpaint.java   
private void uploadImage(final ImageElement element){
    loadedPanel.clear();

    loadedImage=new Image(element.getSrc());
    loadedPanel.add(loadedImage);

    ImageElementUtils.copytoCanvas(element, sharedCanvas);
    //loadedPanel.add(sharedCanvas);

    //add alpha?
    updateBt.setEnabled(true);
    updateMaskBt.setEnabled(true);
    this.selectedElement=element;
    mainTab.selectTab(0);

    //can't drop convert anymore somewhere need wait loading.
    //mainTab.selectTab(3);
    //temporaly doing.,how to drop convert?
    //doInPaint(element,maskImageElement);

}
项目:gwthtml5apps    文件:PoissonImage.java   
@Override
public void execAsync(final String data) {
    new ImageElementLoader().load(data, new ImageElementListener() {

        @Override
        public void onLoad(ImageElement element) {
            done(data,true);
            imageElements.add(element);
        }

        @Override
        public void onError(String url, ErrorEvent event) {

            done(data,false);
        }
    });

}
项目:gwthtml5apps    文件:ImageMaskDataEditor.java   
protected void doCropSrcs() {
    resetCanvas();
    ImageElementUtils.createWithLoader(backgroundDataUrl,new ImageElementListener() {

        @Override
        public void onLoad(ImageElement element) {
            //Window.open(overlayCanvas.toDataUrl(), "hello", null);
            canvas.getContext2d().save();
            canvas.getContext2d().setGlobalCompositeOperation(Composite.DESTINATION_OUT);
            canvas.getContext2d().drawImage(element, 0, 0);//TODO support scale
            canvas.getContext2d().restore();
            updateCanvas();
        }

        @Override
        public void onError(String url, ErrorEvent event) {
            // TODO Auto-generated method stub

        }
    });

}
项目:libgdxcn    文件:AssetDownloader.java   
public void load (String url, AssetType type, String mimeType, AssetLoaderListener<?> listener) {
    switch (type) {
    case Text:
        loadText(url, (AssetLoaderListener<String>)listener);
        break;
    case Image:
        loadImage(url, mimeType, (AssetLoaderListener<ImageElement>)listener);
        break;
    case Binary:
        loadBinary(url, (AssetLoaderListener<Blob>)listener);
        break;
    case Audio:
        loadAudio(url, (AssetLoaderListener<Void>)listener);
        break;
    case Directory:
        listener.onSuccess(null);
        break;
    default:
        throw new GdxRuntimeException("Unsupported asset type " + type);
    }
}
项目:punk-toads    文件:TileLayer.java   
public void draw() {
    int tileSize = tileset.getTileSize();
    int tilesInRow = tileset.getTilesX();

    ImageElement img = tileset.getImgElement();

    canvasLayer.clear();
    Context2d ctx = canvasLayer.getContext();

    for (int i = 0; i < data.length; i++) {
        int x = i * tileSize;

        for (int j = 0; j < data[i].length; j++) {
            int y = j * tileSize;
            int tile = data[i][j];
            if (tile != -1) {
                int tileX = tile % tilesInRow * tileSize;
                int tileY = tile / tilesInRow * tileSize;

                ctx.drawImage(img, tileX, tileY, tileSize, tileSize, x, y, tileSize, tileSize);
            }
        }
    }
    needRedraw = false;
}