Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt图像原始大小_Gwt_Gwt2 - Fatal编程技术网

Gwt图像原始大小

Gwt图像原始大小,gwt,gwt2,Gwt,Gwt2,我使用图像对象通过调用其setPixelSize()方法来调整图像大小,从而将png图像加载为缩略图。我还需要在某个点以整数的形式检索图像的原始大小。如何获得图像的原始大小(宽度、高度) 好的,我找到了一个解决方法:我使用一个虚拟容器(SimplePanel),在不缩放的情况下加载图像,保存其真实尺寸,然后从父对象中移除容器并丢弃新的图像对象。我不知道这是否是一个好的解决办法,但它是有效的。虽然我想知道是否还有其他方法 解决方法的问题:我有一个droplist,可以从中选择逻辑文件夹(包含图像)

我使用图像对象通过调用其setPixelSize()方法来调整图像大小,从而将png图像加载为缩略图。我还需要在某个点以整数的形式检索图像的原始大小。如何获得图像的原始大小(宽度、高度)

好的,我找到了一个解决方法:我使用一个虚拟容器(SimplePanel),在不缩放的情况下加载图像,保存其真实尺寸,然后从父对象中移除容器并丢弃新的图像对象。我不知道这是否是一个好的解决办法,但它是有效的。虽然我想知道是否还有其他方法

解决方法的问题:我有一个droplist,可以从中选择逻辑文件夹(包含图像)。当我选择一个新文件夹,并在显示器上加载新的图像集时,我得到0表示宽度,0表示高度

private void getTrueSize(String fullUrl) {
        Image trueImage = new Image();
        this.tstCon.add(trueImage);
        trueImage.setUrl(fullUrl);
        this.trueHeight = trueImage.getHeight();
        this.trueWidth = trueImage.getWidth();
        //this.tstCon.remove(trueImage);
        //trueImage = null;
        GWT.log("Image [" + this.imgTitle + "] -> height=" + this.trueHeight + " -> width=" + this.trueWidth);//
    }

这是创建新隐藏图像(绝对放置在视口之外)并读取大小的最简单方法。有一个可以读取映像的exif数据的方法,但在这种情况下,这将是过度的。

扩展映像类并实现onAttach()方法。当小部件附加到浏览器的文档时,将调用此方法

public class Thumb extends Image {

    public Thumb(){
        super();
    }

    protected void onAttach(){
        Window.alert(getOffsetHeight()+" "+getOffsetWidth()); //this should give you the original value
        setPixelSize(10,10); // this should be the visible value 
        super.onAttach();
    }
}

如果这不起作用,请尝试实现onLoad()而不是onAttach(),因为将图像添加到DOM后将调用onLoad(),因此它肯定会起作用。

读取图像加载后图像元素的
naturalHeight
naturalWidth

公共面板(){
图像=新图像();
addLoadHandler(this::onLoad);
}
私有void onLoad(@SuppressWarnings(“未使用”)加载事件){
origImageWidth=getNaturalWidth(图像);
origImageHeight=getNaturalHeight(图像);
}
私有静态int getNaturalHeight(图像img){
返回img.getElement().getPropertyInt(“自然高度”);//$NON-NLS-1$
}
私有静态int getNaturalWidth(图像img){
返回img.getElement().getPropertyInt(“naturalWidth”);/$NON-NLS-1$
}

将绝对值放置在视口外的意思是什么?如果图像已附加且您只需调用
setUrl
,则使用css:style=“position:absolute;top:-1000000px”隐藏元素不起作用。