本文整理汇总了Java中com.google.gwt.dom.client.ImageElement.as方法的典型用法代码示例。如果您正苦于以下问题:Java ImageElement.as方法的具体用法?Java ImageElement.as怎么用?Java ImageElement.as使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.dom.client.ImageElement
的用法示例。
在下文中一共展示了ImageElement.as方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findImages
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
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);
}
}
}
示例2: onModuleLoad
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public void onModuleLoad() {
canvas = Canvas.createIfSupported();
if (canvas == null) {
Window.alert("Canvas not supported");
return;
}
RootPanel.get("screen").add(canvas);
CanvasElement el = canvas.getCanvasElement();
el.setWidth(960);
el.setHeight(540);
Context2d ctx = canvas.getContext2d();
setupContext(ctx);
ctx.scale(3, 3);
RootPanel.get().addDomHandler(this, KeyDownEvent.getType());
font = new Image("images/font.png");
fontElement = ImageElement.as(font.getElement());
audio = Audio.createIfSupported();
game = new Game(this);
game.pushState(new WelcomeState(game));
new Timer() {
@Override
public void run() {
game.handleEvent();
game.update();
game.draw();
}
}.scheduleRepeating(50);
}
示例3: scaleImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
private ImageData scaleImage(Image image, double scaleToRatio) {
Canvas canvasTmp = Canvas.createIfSupported();
Context2d context = canvasTmp.getContext2d();
int imageHeight = image.getHeight();
double ch = (imageHeight * scaleToRatio);
int imageWidth = image.getWidth();
double cw = (imageWidth * scaleToRatio);
canvasTmp.setCoordinateSpaceHeight((int) ch);
canvasTmp.setCoordinateSpaceWidth((int) cw);
// TODO: make a temp imageElement?
ImageElement imageElement = ImageElement.as(image.getElement());
// s = source
// d = destination
double sx = 0;
double sy = 0;
int imageElementWidth = imageElement.getWidth();
if (imageElementWidth <= 0) {
imageElementWidth = imageWidth;
}
double sw = imageElementWidth;
int imageElementHeight = imageElement.getHeight();
if (imageElementHeight <= 0) {
imageElementHeight = imageHeight;
}
double sh = imageElementHeight;
double dx = 0;
double dy = 0;
double dw = imageElementWidth;
double dh = imageElementHeight;
// 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 = null;
try {
imageData = context.getImageData(0, 0, w, h);
} catch (Exception e) {
// no image data. we'll try againg...
String b = e.getLocalizedMessage();
}
int ht = (int) h + 10;
int wt = (int) w + 10;
// Clear the div, clear the drawing canvas then reinsert. Otherwise, ghosts of the previous image appear.
canvasDiv.clear();
imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
canvasDiv.add(imageCanvas, 0, 0);
canvasDiv.add(drawingCanvas, 0, 0);
imageCanvas.setCoordinateSpaceHeight(ht);
imageCanvas.setCoordinateSpaceWidth(wt);
drawingCanvas.setCoordinateSpaceHeight(ht);
drawingCanvas.setCoordinateSpaceWidth(wt);
canvasDiv.setSize(wt + "px", ht + "px");
return imageData;
}
示例4: scaleImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
private ImageData scaleImage(double scaleToRatio) {
Canvas canvasTmp = Canvas.createIfSupported();
Context2d context = canvasTmp.getContext2d();
int imageHeight = plotImage.getHeight();
double ch = (imageHeight * scaleToRatio);
int imageWidth = plotImage.getWidth();
double cw = (imageWidth * scaleToRatio);
if ( imageHeight <= 0 || imageWidth <=0 ) {
return null;
}
canvasTmp.setCoordinateSpaceHeight((int) ch);
canvasTmp.setCoordinateSpaceWidth((int) cw);
// TODO: make a temp imageElement?
ImageElement imageElement = ImageElement.as(plotImage.getElement());
// s = source
// d = destination
double sx = 0;
double sy = 0;
int imageElementWidth = imageElement.getWidth();
if (imageElementWidth <= 0) {
imageElementWidth = imageWidth;
}
double sw = imageElementWidth;
int imageElementHeight = imageElement.getHeight();
if (imageElementHeight <= 0) {
imageElementHeight = imageHeight;
}
double sh = imageElementHeight;
double dx = 0;
double dy = 0;
double dw = imageElementWidth;
double dh = imageElementHeight;
// 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 = null;
try {
imageData = context.getImageData(0, 0, w, h);
} catch (Exception e) {
// Well bummer
}
int ht = (int) h + 10;
int wt = (int) w + 10;
// Clear the div, clear the drawing canvas then reinsert. Otherwise, ghosts of the previous image appear.
canvasDiv.clear();
imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
canvasDiv.add(imageCanvas, 0, 0);
canvasDiv.add(drawingCanvas, 0, 0);
imageCanvas.setCoordinateSpaceHeight(ht);
imageCanvas.setCoordinateSpaceWidth(wt);
drawingCanvas.setCoordinateSpaceHeight(ht);
drawingCanvas.setCoordinateSpaceWidth(wt);
canvasDiv.setSize(wt + "px", ht + "px");
return imageData;
}
示例5: scaleImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
private ImageData scaleImage(double scaleToRatio) {
Canvas canvasTmp = Canvas.createIfSupported();
Context2d context = canvasTmp.getContext2d();
int imageHeight = plotImage.getHeight();
double ch = (imageHeight * scaleToRatio);
int imageWidth = plotImage.getWidth();
double cw = (imageWidth * scaleToRatio);
canvasTmp.setCoordinateSpaceHeight((int) ch);
canvasTmp.setCoordinateSpaceWidth((int) cw);
// TODO: make a temp imageElement?
ImageElement imageElement = ImageElement.as(plotImage.getElement());
// s = source
// d = destination
double sx = 0;
double sy = 0;
int imageElementWidth = imageElement.getWidth();
if (imageElementWidth <= 0) {
imageElementWidth = imageWidth;
}
double sw = imageElementWidth;
int imageElementHeight = imageElement.getHeight();
if (imageElementHeight <= 0) {
imageElementHeight = imageHeight;
}
double sh = imageElementHeight;
double dx = 0;
double dy = 0;
double dw = imageElementWidth;
double dh = imageElementHeight;
// 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 = null;
try {
imageData = context.getImageData(0, 0, w, h);
} catch (Exception e) {
// well, bummer
}
int ht = (int) h + 10;
int wt = (int) w + 10;
// Clear the div, clear the drawing canvas then reinsert. Otherwise, ghosts of the previous image appear.
canvasDiv.clear();
imageCanvasContext.clearRect(0, 0, imageCanvas.getCoordinateSpaceWidth(), imageCanvas.getCoordinateSpaceHeight());
canvasDiv.add(imageCanvas, 0, 0);
canvasDiv.add(drawingCanvas, 0, 0);
imageCanvas.setCoordinateSpaceHeight(ht);
imageCanvas.setCoordinateSpaceWidth(wt);
drawingCanvas.setCoordinateSpaceHeight(ht);
drawingCanvas.setCoordinateSpaceWidth(wt);
canvasDiv.setSize(wt+"px", ht+"px");
return imageData;
}
示例6: cloneAndProcessNode
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
private void cloneAndProcessNode() {
Element cloned = Element.as(imgElement.cloneNode(true));
ImageElement ie = ImageElement.as(
DomUtil.getFirstElementByTagNameInc(cloned, "IMG"));
if (!srcUrl.isEmpty()) {
ie.setSrc(srcUrl);
srcUrl = ie.getSrc();
}
// If computed width or height is zero, do not override them
// to keep them visible.
if (width > 0 && height > 0) {
ie.setWidth(width);
ie.setHeight(height);
}
DomUtil.stripImageElement(ie);
NodeList<Element> srcs = cloned.getElementsByTagName("SOURCE");
for (int i = 0; i < srcs.getLength(); i++) {
Element src = srcs.getItem(i);
for (String attr : LAZY_SRCSET_ATTRIBUTES) {
String srcset = src.getAttribute(attr);
if (!srcset.isEmpty()) {
src.setAttribute("srcset", srcset);
break;
}
}
}
DomUtil.makeAllSrcAttributesAbsolute(cloned);
DomUtil.makeAllSrcSetAbsolute(cloned);
clonedImg = cloned;
}
示例7: Image
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
protected Image(Image source) {
super(source);
this.imgElement = ImageElement.as(this.getElement());
this.setSrc(source.src);
this.setAlt(source.alt);
this.widthPx = source.widthPx;
this.heightPx = source.heightPx;
this.keepPropertions = source.keepPropertions;
this.resetSize();
}
示例8: extract
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
@Override
public WebImage extract(Element e) {
if (!relevantTags.contains(e.getTagName())) {
return null;
}
imgSrc = "";
ImageElement ie = ImageElement.as(DomUtil.getFirstElementByTagNameInc(e, "IMG"));
if ("FIGURE".equals(e.getTagName())) {
Element img = DomUtil.getFirstElementByTagName(e, "PICTURE");
if (img == null) {
img = DomUtil.getFirstElementByTagName(e, "IMG");
}
if (img == null) {
return null;
}
extractImageAttributes(ie);
Element figcaption;
Element cap = DomUtil.getFirstElementByTagName(e, "FIGCAPTION");
if (cap != null) {
// We look for links because some sites put non-caption
// elements into <figcaption>. For example: image credit
// could contain a link. So we get the whole DOM structure within
// <figcaption> only when it contains links, otherwise we get the innerText.
NodeList<Element> links = DomUtil.querySelectorAll(cap, "A[HREF]");
figcaption = links.getLength() > 0 ?
cap : createFigcaptionElement(cap);
} else {
figcaption = createFigcaptionElement(e);
}
return new WebFigure(img, width, height, imgSrc, figcaption);
}
if ("SPAN".equals(e.getTagName())) {
if (!e.getAttribute("class").contains("lazy-image-placeholder")) {
return null;
}
// Image lazy loading on Wikipedia.
ie = Document.get().createImageElement();
imgSrc = e.getAttribute("data-src");
width = JavaScript.parseInt(e.getAttribute("data-width"));
height = JavaScript.parseInt(e.getAttribute("data-height"));
ie.setAttribute("srcset", e.getAttribute("data-srcset"));
return new WebImage(ie, width, height, imgSrc);
}
extractImageAttributes(ie);
return new WebImage(e, width, height, imgSrc);
}
示例9: copy
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public ImageElementData copy(){
ImageElement element=ImageElement.as(DOM.createImg());
element.setSrc(imageElement.getSrc());
ImageElementData newData=new ImageElementData(getFileName(),element,getDataUrl());
return newData;
}
示例10: asImageElement
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public static ImageElement asImageElement(ImageResource imageResource) {
return ImageElement.as((new Image(imageResource.getSafeUri())).getElement());
}
示例11: drawImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
/**
* Draws the given image in the receiver at the specified coordinates.
*
* @param image
* the image to draw
* @param x
* the x coordinate of where to draw
* @param y
* the y coordinate of where to draw
*
* @exception IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the image is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the image has been
* disposed</li>
* <li>ERROR_INVALID_ARGUMENT - if the given coordinates are
* outside the bounds of the image</li>
* @exception SWTException
* <ul>
* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
* disposed</li>
* </ul>
* @exception SWTError
* <ul>
* <li>ERROR_NO_HANDLES - if no handles are available to
* perform the operation</li>
* </ul>
*/
public void drawImage(Image image, int x, int y) {
if (image.gwtImage == null) {
System.err.println("drawImage failed: image.gwtImage is null");
return;
}
final ImageElement imageElement = ImageElement.as(image.gwtImage
.getElement());
imageElement.setSrc(image.gwtImage.getUrl());
context2d.save();
reInitContext2d();
context2d.drawImage(imageElement, x, y);
context2d.restore();
}