【问题标题】:Give source of image on SD card to image tag in phonegap将 SD 卡上的图像来源提供给 phonegap 中的图像标签
【发布时间】:2013-09-17 11:10:56
【问题描述】:

我想将图像源分配给 html 中的 img 标签。图像保存在 sdcard 的自定义文件夹中。请帮我这样做。我对此进行了很多搜索,但没有任何帮助。

【问题讨论】:

    标签: android image cordova android-sdcard src


    【解决方案1】:

    我只是通过提供路径来解决它

    <img src="file:///mnt/sdcard/abc/def/ghi/xyz.png"/>
    

    【讨论】:

      【解决方案2】:

      这就是我将如何解决您的问题:

      function getPathToCustomFolder(callback)
      {               
       var customFolderName = "myFunnyImages"
       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,                  
        function(fileSys) {
         fileSys.root.getDirectory(customFolderName, {create: true, exclusive: false}, 
                          function(dir){
          callback(dir.fullPath);
         })
        }, error
       );
      }
      
      // After calling this function, you will get the path of your customFolder   
      function alertThePath()
      {
       getPathToCustomFolder(
        function(result){
         alert(result);
        });
      }
      
      // Changes your scr attribute
      function showMyImage()
      {
       var image = document.getElementById('funnyImage');
       getPathToCustomFolder(
        function(result){
         image.src = result+"/funny1.jpg";
       });
      }
      

      有关更多信息,请查看 phonegap FileAPI。

      【讨论】:

      • 感谢您的回答@bpichon。但正如我所提到的,一行已经解决了我的问题,这正是 dir.fullpath 值。
      猜你喜欢
      • 1970-01-01
      • 2015-12-27
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多