ClientBundle 不加载 ImageResource

发布于 2024-11-25 07:13:51 字数 1707 浏览 1 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2024-12-02 07:13:51

不保证图像内容同步加载。根据浏览器的功能和图像数据的大小,资源可能会存储为独立文件,这似乎就是您所描述的情况(即 cache.png)。这样的公式有什么区别吗?

final Image img = new Image(ResourceBundle.INSTANCE.smiley());
img.addLoadHandler(new LoadHandler() {
  public void onLoad(LoadEvent e) {
    c.drawImage((ImageElement) img.getElement());
  }
}
RootPanel.get().add(img);

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?

final Image img = new Image(ResourceBundle.INSTANCE.smiley());
img.addLoadHandler(new LoadHandler() {
  public void onLoad(LoadEvent e) {
    c.drawImage((ImageElement) img.getElement());
  }
}
RootPanel.get().add(img);
白况 2024-12-02 07:13:51

如果您在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文