2017-06-16 5 views
1

iOSのストレージに画像を保存しようとして問題が発生しました。イメージはダウンロードされますが保存されません。iOS保存に問題が発生する

コードは次のとおりです。https://www.codenameone.com/javadoc/com/codename1/ui/URLImage.html

木から取った

 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(); 

は画像がストレージに保存されたかどうかを確認するだけです。

答えて

0

あなたは混合していますStorage & FileSystemStorageこれは非常に異なるものですthisを参照してください。

"ファイル"のフラットセットであるストレージを使用できます。これはURLImage.createToStorageの機能です。しかし、そのためにはStorage APIを使用する必要があり、FileSystemStorage APIには表示されないことがあります。

また、URLImage.createToFileSystem()を探している可能性があります。

関連する問題