GWT create Image using ImageResource

吃可爱长大的小学妹 提交于 2019-12-13 12:29:10

问题


My question is really simple and shot. but hope I can have a clear answer. We can create GWT Image in many ways.

Image image = new Image ( (ImageResource)imageRes);

Image image = new Image ( (ImageResource)imageRes.getSafeUri() );

Image image = new Image ();
image.setUrl((ImageResource)imageRes.getSafeUri().asString() );

My question is: what are the difference among these 3 ways to create a new image using ImageResouce. Which one is best or faster for first-time loading?

Thanks


回答1:


First, you should not use the last two.

An ImageResource technically represents a region within a "sprited" image: it has a URL to the sprite and the coordinates of the region on that image. In many browsers, and for most images, the URL will actually be a data: URL and the region will represent the whole image. This can be controlled on a per-image basis using @ImageOptions(preventInlining=true) or globally with a set-property on your gwt.xml. In other words, your code shouldn't rely on it, and should always treat an ImageResource as a region within a sprited image.
FYI, the cases where a sprited image is actually used by default are for IE6/7 which does not support data: URLs, and for images that are too large to fit within a data: URL (all browsers).

This is however exactly what you're doing in the last two cases: use only the URL of the ImageResource, as if it weren't (potentially) a sprited image.



来源:https://stackoverflow.com/questions/11674279/gwt-create-image-using-imageresource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!