codenameone - 从存储加载图像
问题描述
我有一个使用 URLImage 类加载的图像。这是代码:
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(getWidth()/2, getWidth()/2 , 0xF92D2D), true);
Image originImg = URLImage.createToStorage(placeholder, imgFileName, photo_url);
据我了解,此图像正在使用createToStorage()
方法保存到存储中。但是,下次加载此表单时,我不想再次下载图像,我想从存储中获取它,因为它更快。所以我做了什么,我添加了检查:
if (Storage.getInstance().exists(imgFileName)) {
// Take the image from the Storage
originImg = Image.createImage(Storage.getInstance().createInputStream(imgFileName));
} else {
// Load the image with URLImage class.
}
但是,似乎我的文件从未保存到存储中。有什么问题?
解决方案
你不需要这样做。URLImage
如果文件已经存在,则从存储中无缝加载文件。您可以打开网络监视器并查看是否对该特定图像的 URL 发出了请求。
我不确定为什么该Storage.getInstance().exists(imgFileName)
方法会失败。我假设图像名称在不同的执行或类似的东西中是不同的。您可以看到在您的.cn1
目录中创建了图像。
推荐阅读
- java - 查找 java.security.Security 中所有属性的当前状态
- java - 如何在 Crafter CMS 中设置站点?
- java - 将 ImageView 调整为所有可用空间
- c++ - C++ 中的非阻塞套接字 - 资源暂时不可用错误
- javascript - 相同的类型和相同的单词,但在询问它们是否相同时仍然返回 false
- c# - WPF 使用 Linq 将列表框绑定到 2 个表
- docusignapi - 将文本框字段和选项列表添加到通过 DocuSignAPI 发送的 pdf
- sql - 优化一个有大量记录被连接和组合的 sql 查询
- sql - 同一个外键如何在 SQL 中有多个引用?
- razor - Razor 如何区分 @ 符号的使用?