Javascript 如何将图像从服务器加载到phonegap中的img文件夹

Javascript 如何将图像从服务器加载到phonegap中的img文件夹,javascript,android,jquery,cordova,cordova-plugins,Javascript,Android,Jquery,Cordova,Cordova Plugins,我已经开发了一个游戏,它有更多的图像,所以我想从服务器上加载我的phonegap游戏中完成的每个游戏级别的图像。 我需要将图像从服务器下载到此位置 file:///android_asset/www/img 在phonegap游戏中 我怎样才能做到这一点 我已经读完了教程 但是在这里他们已经在屏幕上显示了图像,我不想把它们保存在img文件夹中 函数库IntelligrapeLogo{ //警报“文件下载开始”; var url=;//图像url window.requestFileSystemL

我已经开发了一个游戏,它有更多的图像,所以我想从服务器上加载我的phonegap游戏中完成的每个游戏级别的图像。 我需要将图像从服务器下载到此位置

file:///android_asset/www/img 在phonegap游戏中

我怎样才能做到这一点

我已经读完了教程 但是在这里他们已经在屏幕上显示了图像,我不想把它们保存在img文件夹中

函数库IntelligrapeLogo{ //警报“文件下载开始”; var url=;//图像url window.requestFileSystemLocalFileSystem.PERSISTENT,0,functionfs{ //警报“内部请求文件系统” //fs.root.getDirectorymyFolderName,{create:true,exclusive:false},函数文件夹{}

      var imagePath = 'file:///storage/sdcard0'+fs.root.fullPath + "/logo2.png"; // full file path
      // var imagePath = 'file:///android_asset/www/'+fs.root.fullPath + "logo2.png";

       // alert('inside request file sysytem path fs.root==' + fs.root);
       // alert('inside request file sysytem path fs.root.fullPath==' + fs.root.fullPath);
        var fileTransfer = new FileTransfer();
        fileTransfer.download(url, imagePath, function(entry) {
           // alert(entry.fullPath); // entry is fileEntry object
            var dwnldImg = document.getElementById("dwnldImg");
            dwnldImg.src = imagePath;
            dwnldImg.style.visibility = "visible";
            dwnldImg.style.display = "block";

        }, function(error) {
            alert("Some error" + JSON.stringify(error));
        });
    }) } 
我已经尝试过这个例子,但是它将图像存储在phone memory中,但是我需要将图像存储到phonegap img文件夹中

提前感谢使用此代码:

/**
 * Load an image from internet and save it under the default repertory of the application
 */
public void downloadImageFromInternet(String url, String name)
{
    ImageLoader.getInstance().loadImage(url, 
        new SimpleImageLoadingListener()
        {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
            {
                OutputStream fOut;

                // You need to reference your context here. Depending on the class you inherite, "this", "getContext()" or "getActivity()" could work 
                File file = new File(context.getFilesDir(), name + ".jpeg");

                try
                {
                    fOut = new FileOutputStream(file);

                    loadedImage.compress(Bitmap.CompressFormat.JPEG, 90, fOut);

                    fOut.flush();
                    fOut.close();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
        });
}
阅读文档以了解如何设置保存文件的路径。在此代码中,文件将保存在应用程序的默认文件夹中


您需要从web下载图像的库是。

从服务器以字符串Base64的形式发送图像,并使用phonegap中的Javascript将其转换为androidI am中的文件。您能给出Jquery、Javascript或phonegap插件代码吗?