【问题标题】:is it possible to load images from the directory on web server?是否可以从 Web 服务器上的目录加载图像?
【发布时间】:2013-08-12 18:41:47
【问题描述】:

我目前正在使用 nostra 图像加载器来加载图像... 在我的代码中我是这样使用的..

 public static final String[] IMAGES = {"http://mywebsite.com/tittle/image1.jpg",
        "http://mywebsite.com/tittle/image2.jpg",
        "http://mywebsite.com/tiitle/image3.jpg",
        "http://mywebsite.com/tittle/image4.jpg",
        "http://mywebsite.com/tittle/image5.jpg",....};

是否可以从包含图像的目录中加载图像.. 比如“”http://mywebsite.com/tittle

【问题讨论】:

  • 你的意思是说你想从网站的tittle文件夹下载图片而不给出具体的图片名称?我是对还是错?

标签: android image http directory universal-image-loader


【解决方案1】:

您想从一个目录下载所有图像对吗?

File directory= new File("some public directory");
for (File file : directory.listFiles())
{
   if (FileNameUtils.getExtension(file.getName()).equals("jpg"))
   {
      //get file here
   }
}

【讨论】:

  • 会试一试告诉你
【解决方案2】:

你的问题不清楚。您能否详细说明您要使用哪个目录。是SD卡目录(外存)、手机目录(内存)还是网络服务器上的目录。

仍然是答案,您可以从上述所有 3 个记忆中加载图像。

这是从网络服务器下载任何图像并将其保存到本地内存的过程:

public class DownloadImage
{
   public DownloadImage(String url,String file) throws IOException
   {
        File fileName = new File(file);
        URL myImageURL = new URL(url);
        HttpURLConnection connection = (HttpURLConnection)myImageURL.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        OutputStream fOut = null;
        fOut = new FileOutputStream(fileName);
        myBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();

   }
}

创建一个名为 DownloadImage 的新类并复制上面的代码。然后在“url”中传递必须下载图像的HTTP Url,在“file”中传递必须存储图像的本地内存地址。

【讨论】:

  • 你认为sd卡目录和电话目录有http链接吗...问题是关于web服务器的
  • 相信我已经回答过了。是的,可以从文件夹中加载
  • 我相信这就是你要找的@DivyaRamakrishnan
  • 这不是我要找的……我想加载一堆图像。我不能写所有这些图像字符串 url。所以我想从图像具有的父目录加载图像在网络服务器上?
  • 如果你想下载一个文件夹然后你需要学习 Apache VFS,这个链接可能对你有帮助。 stackoverflow.com/questions/1724589/…
猜你喜欢
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
相关资源
最近更新 更多