URLImage 获取方法不起作用
URLImage fetch method not working
我查看了文档:https://www.codenameone.com/javadoc/com/codename1/ui/URLImage.html#fetch
By default an image is fetched lazily as it is asked for by the GUI unless the fetch() method is invoked in which case the IO code is executed immediately.
调用 fetch() 后存储文件似乎没有刷新。这是我的测试 运行
1) 我第一次创建 URL 图像时使用以下图像:“https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png”
2) 我运行申请了。图像显示良好
3) 我用新 URL 图像“http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg”重新 运行 应用程序,但尽管正在调用 fetch(),但我仍然看到以前的图像!
Form hi = new Form("Hi World");
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
background.fetch();
Label label = new Label();
label.setIcon(background);
hi.addComponent(label);
hi.show();
第二个运行:
Form hi = new Form("Hi World");
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
"http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg");
background.fetch();
Label label = new Label();
label.setIcon(background);
hi.addComponent(label);
hi.show();
文档可能应该得到澄清,立即并不意味着同步,因此 fetch 方法只会将图像添加到下载队列中,但在图像实际存在之前不会阻塞。
如果你想要那种行为 URL 图片可能不是最好的解决方案。您可以使用 Util.downloadToStorage()
或 ConnectionRequest
中的 Image
下载方法以及 addToQueueAndWait
.
我查看了文档:https://www.codenameone.com/javadoc/com/codename1/ui/URLImage.html#fetch
By default an image is fetched lazily as it is asked for by the GUI unless the fetch() method is invoked in which case the IO code is executed immediately.
调用 fetch() 后存储文件似乎没有刷新。这是我的测试 运行
1) 我第一次创建 URL 图像时使用以下图像:“https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png”
2) 我运行申请了。图像显示良好
3) 我用新 URL 图像“http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg”重新 运行 应用程序,但尽管正在调用 fetch(),但我仍然看到以前的图像!
Form hi = new Form("Hi World");
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
"https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
background.fetch();
Label label = new Label();
label.setIcon(background);
hi.addComponent(label);
hi.show();
第二个运行:
Form hi = new Form("Hi World");
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
URLImage background = URLImage.createToStorage(placeholder, "400px-AGameOfThrones.jpg",
"http://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg");
background.fetch();
Label label = new Label();
label.setIcon(background);
hi.addComponent(label);
hi.show();
文档可能应该得到澄清,立即并不意味着同步,因此 fetch 方法只会将图像添加到下载队列中,但在图像实际存在之前不会阻塞。
如果你想要那种行为 URL 图片可能不是最好的解决方案。您可以使用 Util.downloadToStorage()
或 ConnectionRequest
中的 Image
下载方法以及 addToQueueAndWait
.