2

I am currently using nostra image loader for loading images... in my code i am using like this..

 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",....};

Is it possible load images from the directory which has images in it.. like ""http://mywebsite.com/tittle"

4

2 回答 2

3

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

File directory= new File("some public directory");
for (File file : directory.listFiles())
{
   if (FileNameUtils.getExtension(file.getName()).equals("jpg"))
   {
      //get file here
   }
}
于 2013-08-13T07:53:18.040 回答
1

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

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

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

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”中传递必须存储图像的本地内存地址。

于 2013-08-11T09:27:39.030 回答