ClientBundle 不加载 ImageResource
我尝试使用 ClientBundle 实现将图像管理到大文件并最小化 HTTP 请求。
我在 gwt.xml 中
生成 ClientBundle
公共接口 ResourceBundle 扩展 ClientBundle {
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
@Source("tiles/smiley.png")
ImageResource smiley();
}
将找到图像,没有错误。
这是代码
@Override public void onModuleLoad() {
CLogger.log("Start Engine");
int width = 800;
int height = 600;
Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(width + "px");
canvas.setHeight(height + "px");
canvas.setCoordinateSpaceWidth(width);
canvas.setCoordinateSpaceHeight(height);
Context2d c = canvas.getContext2d();
Image img = new Image(ResourceBundle.INSTANCE.smiley());
img.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
CLogger.log(event.getSource() + " loaded");
}
});
CLogger.log("Visible: " + img.isVisible());
c.drawImage((ImageElement) new Image(ResourceBundle.INSTANCE.smiley()).getElement().cast(), 0, 0);
RootPanel.get().add(canvas);
}
我创建一个简单的 Canvas 并将大小设置为 800x600。我创建一个新的 Context2D 对象来在 Context 处绘制图像并将 Canvas 添加到 RootPanel。
日志显示:
[20:10:21.676] - 启动引擎 [20:10:21.851] - 可见:true [20:10:21.853] - http://127.0.0.1:8888/engine/7D39451825E9952050F44A6B8E2E15F3.cache.png
图像存在于记录的 URL 下,因此一切看起来都很好。但图像不会被绘制,或者它会绘制但不显示。
有人有想法吗?
我认为 ClientBundle 加载图像作为后端的开始。那么,如果我得到一个实例,每个图像/CSS 和其他内容都会被加载吗?
问候马库斯
I try to use the ClientBundle implementation to manage my Images to a large File and minimize the HTTP-Requests.
I put in my gwt.xml
Generate the ClientBundle
public interface ResourceBundle extends ClientBundle {
public static final ResourceBundle INSTANCE = GWT.create(ResourceBundle.class);
@Source("tiles/smiley.png")
ImageResource smiley();
}
The Image would be found, no errors.
Here is the code
@Override
public void onModuleLoad() {
CLogger.log("Start Engine");
int width = 800;
int height = 600;
Canvas canvas = Canvas.createIfSupported();
canvas.setWidth(width + "px");
canvas.setHeight(height + "px");
canvas.setCoordinateSpaceWidth(width);
canvas.setCoordinateSpaceHeight(height);
Context2d c = canvas.getContext2d();
Image img = new Image(ResourceBundle.INSTANCE.smiley());
img.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
CLogger.log(event.getSource() + " loaded");
}
});
CLogger.log("Visible: " + img.isVisible());
c.drawImage((ImageElement) new Image(ResourceBundle.INSTANCE.smiley()).getElement().cast(), 0, 0);
RootPanel.get().add(canvas);
}
I create a simple Canvas and set the size to 800x600. I create a new Context2D Object to draw the Image at the Context and add the Canvas to the RootPanel.
The logs shows:
[20:10:21.676] - Start Engine
[20:10:21.851] - Visible: true
[20:10:21.853] - http://127.0.0.1:8888/engine/7D39451825E9952050F44A6B8E2E15F3.cache.png
The Image exists under the logged URL so everything looks fine. But the Image would not be draw or it would draw but not display.
Anybody an idea?
I thought the ClientBundle loads the Images as the start in the backend. So if I get an Instance every Image/Css and others fill be loaded?
Regars Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不保证图像内容同步加载。根据浏览器的功能和图像数据的大小,资源可能会存储为独立文件,这似乎就是您所描述的情况(即
cache.png
)。这样的公式有什么区别吗?Image contents aren't guaranteed to be loaded synchronously. Depending on the capabilities of the browser and the size of the image data, the resource may be stored as a standalone file, which appears to be the case that you're describing (i.e.
cache.png
). Does a formulation like this make any difference?如果您在 UiBinder 之外使用 CSSResources 和 ImageBundles,则必须确保正确注入 stlyesheet 和图像。
请参阅此处了解更多信息。
If you use CSSResources and ImageBundles outside of UiBinder you have to make sure that the stlyesheet and images are injected properly.
See here for more information.