本文整理汇总了Java中com.google.gwt.user.client.ui.Image.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Image.getWidth方法的具体用法?Java Image.getWidth怎么用?Java Image.getWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.user.client.ui.Image
的用法示例。
在下文中一共展示了Image.getWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWidth
import com.google.gwt.user.client.ui.Image; //导入方法依赖的package包/类
/**
* Returns the original width when when using IE.
*
* @see com.google.gwt.user.client.ui.Image#getWidth()
*/
@Override
public int getWidth() {
int superWidth = super.getWidth();
logger.log(Level.INFO, "superWidth:" + superWidth);
logger.log(Level.INFO, "isAttached():" + isAttached());
if ( (superWidth <= 0) ) {
// If this is being run under IE the default answer may be 0 when it
// shouldn't be, so return the height from a hidden and attached
// temp image
Image temp = new Image(this.getUrl());
temp.getElement().getStyle().setVisibility(Visibility.HIDDEN);
RootPanel.get().add(temp);
logger.log(Level.WARNING, "temp.isAttached():" + temp.isAttached());
int tempWidth = temp.getWidth();
logger.log(Level.WARNING, "tempWidth:" + tempWidth);
temp.removeFromParent();
return tempWidth;
}
return superWidth;
}
示例2: loadImage
import com.google.gwt.user.client.ui.Image; //导入方法依赖的package包/类
/**
* Shows a resource as the {@code <img>} element.
*/
public void loadImage(String url) {
ClientUtils.setMembers(display, imgContainer);
image = new Image();
image.addLoadHandler(this);
image.addErrorHandler(this);
image.setUrl(url);
drawHandler = imgContainer.addDrawHandler(this);
resizedHandler = imgContainer.addResizedHandler(this);
ClientUtils.fine(LOG, "loadImage url: %s, width: %s", url, image.getWidth());
if (image.getWidth() == 0) {
WidgetCanvas widgetCanvas = new WidgetCanvas(image);
widgetCanvas.setVisible(false);
widgetCanvas.setWidth(1);
widgetCanvas.setHeight(1);
widgetCanvas.draw();
Img loadingImg = new Img("[SKIN]/loadingSmall.gif", 16, 16);
// Img loadingImg = new Img("[SKIN]/shared/progressCursorTracker.gif", 16, 16);
loadingImg.setAltText(i18n.ImportBatchDataSource_State_LOADING());
loadingImg.setPrompt(i18n.ImportBatchDataSource_State_LOADING());
loadingImg.setLayoutAlign(Alignment.CENTER);
imgContainer.setMembers(loadingImg, widgetCanvas);
}
scheduleForRender();
}
示例3: scaleImage
import com.google.gwt.user.client.ui.Image; //导入方法依赖的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: setWidgetPixPosition
import com.google.gwt.user.client.ui.Image; //导入方法依赖的package包/类
/**
* set position of a widget as the widget is centered on the given position.
* @param p_w
* @param p_wgtPixPosition position in pixel
*/
public void setWidgetPixPosition(Image p_w, AnPair p_wgtPixPosition)
{
super.setWidgetPosition( p_w, p_wgtPixPosition.getX() - p_w.getWidth() / 2, p_wgtPixPosition
.getY()
- p_w.getHeight() / 2 );
// p_w.setVisible( true );
}