URLImage不总是加载

3
使用URLImage时,如果没有添加代码中的Label lb=new Image(img)这一行,我只有偶尔能从网络服务器获取图像(在网络监视器中查看没有请求)。当我添加了这个“虚假”标签后,每次都可以获取到图像。
有没有办法确保每次加载图像而不需要这个虚假标签呢?还有一个额外的问题:有没有一种方法可以查看图片何时被加载?或者有关于它的事件?
我的代码如下:
        ryd_storage("skytteimage", true);
        EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(CN.getDisplayWidth(),CN.getDisplayWidth(), 0xf0f00000), false);
        URLImage img;
        String hurl="https://frederikssund-bueskydning.dk/medlemmer/profil/" +pc;
        img = URLImage.createToStorage(placeholder, "skytteimage",hurl, URLImage.RESIZE_SCALE_TO_FILL);
        img.fetch();
        Label lb=new Label(img);
1个回答

1

URLImage旨在实现无缝连接。它的目的是为了展示而不是单纯的下载,因此在这方面它异步处理时会存在一些次优之处。它不提供任何事件(再次强调无缝连接的重要性)。

我假设您只想将图像下载到存储中,这可以使用ConnectionRequest来完成:

ConnectionRequest cr = new ConnectionRequest(imageUrl, false);
cr.downloadImageToStorage(imageStorageFileName, img -> {
    // you will get an img object here and it's cached in the file system
});

谢谢,正是我所需要的。 - Flemming Schwicker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接