本文整理汇总了Java中com.google.gwt.dom.client.ImageElement.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java ImageElement.getWidth方法的具体用法?Java ImageElement.getWidth怎么用?Java ImageElement.getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.dom.client.ImageElement
的用法示例。
在下文中一共展示了ImageElement.getWidth方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paint
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
@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);
}
}
}
示例2: 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);
}
}
}
示例3: extractImageAttributes
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
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);
}
}
示例4: updateBgImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
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);
}
}
示例5: setPicDataLowLevel
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public void setPicDataLowLevel(Image image, ImageElement img) {
CanvasElement canvas = (CanvasElement) Document.get().createElement("canvas");
int w = img.getWidth();
int h = img.getHeight();
canvas.setWidth(w);
canvas.setHeight(h);
// canvas.getStyle().setProperty("border", "solid 1px green");
canvas.getStyle().setDisplay(Display.NONE);
Document.get().getBody().appendChild(canvas);
CanvasRenderingContext2D ctx = canvas.getContext2D();
ctx.drawImage(img, 0, 0);
ImageData data = ctx.getImageData(0, 0, w, h);
CanvasPixelArray pixels = data.getData();
int count = w * h * 4;
byte[] pic = new byte[count];
for (int i = 0; i < count; i += 4) {
pic[i + 3] = (byte) pixels.get(i + 3); // alpha, then bgr
pic[i + 2] = (byte) pixels.get(i + 2);
pic[i + 1] = (byte) pixels.get(i + 1);
pic[i] = (byte) pixels.get(i);
}
image.setData(pic, w, h, 32);
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: isImageRelevantBySize
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
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;
}
示例10: setPicDataHighLevel
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public void setPicDataHighLevel(Image image, ImageElement img) {
image.has_alpha = true;
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);
}
示例11: __setPicDataHighLevel
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
public void __setPicDataHighLevel(Image image, ImageElement img) {
image.has_alpha = true;
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);
}
示例12: drawImage
import com.google.gwt.dom.client.ImageElement; //导入方法依赖的package包/类
protected void drawImage(
ImageElement image, Context2d context, int row, int column, double scale) {
int width = (int) (image.getWidth() * scale);
int height = (int) (image.getHeight() * scale);
int xOffset = (cellWidth - width) / 2;
int yOffset = (cellHeight - height) / 2;
context.drawImage(image, column * cellWidth + xOffset, row * cellHeight + yOffset,
width, height);
}