GWT使用ImageResource创建图像 [英] GWT create Image using ImageResource

查看:140
本文介绍了GWT使用ImageResource创建图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题非常简单,但希望我能有一个明确的答案。
我们可以通过多种方式创建GWT图像。

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

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

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

我的问题是:使用ImageResouce创建新图像的3种方法有什么区别。第一次加载哪一个最好或更快?



谢谢

解决方案



一个 ImageResource 在技术上代表一个区域内的一个区域, sprited图像:它有一个指向精灵的URL和该图像上区域的坐标。在许多浏览器和大多数图像中,URL实际上都是 data: URL,该区域将表示整个图像。这可以通过使用 @ImageOptions(preventInlining = true)或全局地使用 set-property 在你的 gwt.xml 上。换句话说,你的代码不应该依赖它,并且应该总是把一个 ImageResource 作为一个被添加图像的区域。

FYI,the实际上使用spr图像的情况默认情况下是针对不支持 data: URL的IE6 / 7,对于图像太大以适应数据: URL(所有浏览器)。



然而,这正是你在做的最后两种情况:只使用 ImageResource 的URL,就好像它不是(可能)是一个spr图片。


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

解决方案

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.

这篇关于GWT使用ImageResource创建图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆