Codenameone iOS保存到存储问题
我在尝试将映像保存到iOS中的存储时遇到问题。图像已下载但未保存 代码是:Codenameone iOS保存到存储问题,codenameone,Codenameone,我在尝试将映像保存到iOS中的存储时遇到问题。图像已下载但未保存 代码是: Form hi = new Form("Toolbar", new BoxLayout(BoxLayout.Y_AXIS)); TreeModel tm = new TreeModel() { @Override public Vector getChildren(Object parent) { String[] files;
Form hi = new Form("Toolbar", new BoxLayout(BoxLayout.Y_AXIS));
TreeModel tm = new TreeModel() {
@Override
public Vector getChildren(Object parent) {
String[] files;
if (parent == null) {
files = FileSystemStorage.getInstance().getRoots();
return new Vector<Object>(Arrays.asList(files));
} else {
try {
files = FileSystemStorage.getInstance().listFiles((String) parent);
} catch (IOException err) {
Log.e(err);
files = new String[0];
}
}
String p = (String) parent;
Vector result = new Vector();
for (String s : files) {
result.add(p + s);
}
return result;
}
@Override
public boolean isLeaf(Object node) {
return !FileSystemStorage.getInstance().isDirectory((String) node);
}
};
Command tree = new Command("Show tree") {
@Override
public void actionPerformed(ActionEvent evt) {
Form treeForm = new Form("Tree", new BorderLayout());
Tree t = new Tree(tm) {
@Override
protected String childToDisplayLabel(Object child) {
String n = (String) child;
int pos = n.lastIndexOf("/");
if (pos < 0) {
return n;
}
return n.substring(pos);
}
};
treeForm.add(BorderLayout.CENTER, t);
Command back = new Command("Back") {
@Override
public void actionPerformed(ActionEvent evt) {
hi.showBack();
}
};
Button backButton = new Button(back);
treeForm.add(BorderLayout.SOUTH, backButton);
treeForm.show();
}
};
hi.getToolbar().addCommandToOverflowMenu(tree);
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(hi.getWidth(), hi.getWidth() / 5, 0xffff0000), true);
String photoURL = "https://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg";
StringBuilder fsPath = new StringBuilder(FileSystemStorage.getInstance().getAppHomePath());
fsPath.append("400px-AGameOfThrones.jpg");
URLImage background = URLImage.createToStorage(placeholder, fsPath.toString(), photoURL);
background.fetch();
Style stitle = hi.getToolbar().getTitleComponent().getUnselectedStyle();
stitle.setBgImage(background);
stitle.setBackgroundType(Style.BACKGROUND_IMAGE_SCALED_FILL);
stitle.setPaddingUnit(Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS, Style.UNIT_TYPE_DIPS);
stitle.setPaddingTop(15);
SpanButton credit = new SpanButton("Link");
credit.addActionListener((e) -> Display.getInstance().execute("https://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));
hi.add(new SpanLabel("A")).
add(new Label("B", "Heading")).
add(credit);
ComponentAnimation title = hi.getToolbar().getTitleComponent().createStyleAnimation("Title", 200);
hi.getAnimationManager().onTitleScrollAnimation(title);
hi.show();
Form hi=新表单(“工具栏”,新的BoxLayout(BoxLayout.Y_轴));
TreeModel tm=新的TreeModel(){
@凌驾
公共向量getChildren(对象父对象){
字符串[]文件;
如果(父项==null){
files=FileSystemStorage.getInstance().getRoots();
返回新向量(Arrays.asList(files));
}否则{
试一试{
files=FileSystemStorage.getInstance().listFiles((字符串)父级);
}捕获(IOException err){
Log.e(err);
files=新字符串[0];
}
}
字符串p=(字符串)父级;
向量结果=新向量();
用于(字符串s:文件){
结果:添加(p+s);
}
返回结果;
}
@凌驾
公共布尔isLeaf(对象节点){
return!FileSystemStorage.getInstance().isDirectory((字符串)节点);
}
};
命令树=新命令(“显示树”){
@凌驾
已执行的公共无效操作(操作事件evt){
表单treeForm=新表单(“树”,新边框布局());
树t=新树(tm){
@凌驾
受保护的字符串childToDisplayLabel(对象子对象){
字符串n=(字符串)子级;
int pos=n.lastIndexOf(“/”);
如果(位置<0){
返回n;
}
返回n.子串(pos);
}
};
treeForm.add(BorderLayout.CENTER,t);
命令返回=新命令(“返回”){
@凌驾
已执行的公共无效操作(操作事件evt){
嗨,展示();
}
};
按钮后退按钮=新按钮(后退);
添加(BorderLayout.SOUTH,backButton);
treeForm.show();
}
};
hi.getToolbar().addCommandToOverflowMenu(树);
EncodedImage占位符=EncodedImage.createFromImage(Image.createImage(hi.getWidth(),hi.getWidth()/5,0xffff0000),true);
字符串photoURL=”https://awoiaf.westeros.org/images/thumb/9/93/AGameOfThrones.jpg/400px-AGameOfThrones.jpg";
StringBuilder fsPath=新的StringBuilder(FileSystemStorage.getInstance().getAppHomePath());
append(“400px agameoftrones.jpg”);
URLImage background=URLImage.createToStorage(占位符,fsPath.toString(),photoURL);
background.fetch();
Style-stitle=hi.getToolbar().getTitleComponent().getUnselectedStyle();
针线.背景(背景);
拼接.收进背景类型(样式.背景\图像\缩放\填充);
缝合。设置填充单位(Style.UNIT\u TYPE\u DIPS,Style.UNIT\u TYPE\u DIPS,Style.UNIT\u TYPE\u DIPS,Style.UNIT\u TYPE\u DIPS);
针线设置填充顶(15);
span按钮信用=新span按钮(“链接”);
credit.addActionListener((e)->Display.getInstance().execute(“https://awoiaf.westeros.org/index.php/A_Game_of_Thrones"));
hi.add(新标签(“A”))。
添加(新标签(“B”、“标题”))。
增加(信贷);
ComponentAnimation title=hi.getToolbar().getTitleComponent().createStyleAnimation(“title”,200);
hi.getAnimationManager().onTitleScrollAnimation(标题);
嗨,show();
这是从
该树仅用于查看映像是否保存在存储中。您正在混合
存储
和文件系统存储
,这是非常不同的内容
您可以使用存储,它是一组扁平的“文件”,这就是urlmimage.createToStorage
的作用。但是您需要使用存储
API来处理它,并且它可能在文件系统存储
API中不可见
或者,您可能正在寻找
URLImage.createToFileSystem()
您正在混合存储
和文件系统存储
,这是非常不同的东西
您可以使用存储,它是一组扁平的“文件”,这就是urlmimage.createToStorage
的作用。但是您需要使用存储
API来处理它,并且它可能在文件系统存储
API中不可见
或者,您可能正在查找URLImage.createToFileSystem()