【问题标题】:How to Store Images from URL in Array如何将 URL 中的图像存储在数组中
【发布时间】:2014-10-01 02:27:20
【问题描述】:

我想从 URL 将图像存储在数组中,但我不知道如何实现此功能。

就像我将可绘制的图像存储在数组中一样,我想将图像从 URL 存储在数组中。

可绘制示例:

public Integer[] mThumbIds = {
            R.drawable.pic_1, R.drawable.pic_2,
            R.drawable.pic_3, R.drawable.pic_4,
            R.drawable.pic_5, R.drawable.pic_6,
            R.drawable.pic_7, R.drawable.pic_8,
            R.drawable.pic_9, R.drawable.pic_10,
            R.drawable.pic_11, R.drawable.pic_12,
            R.drawable.pic_13, R.drawable.pic_14,
            R.drawable.pic_15
    };

我试过了,但没用:

public Integer[] mThumbIds = {
            R.string.http_icons_iconarchive_com_icons_martz90_circle_512_android_icon_png

    };

【问题讨论】:

  • 不工作是什么意思?您的预期是什么,发生了什么?
  • 将所有需要的图片 url 存储在一个数组中并将其加载到 imageview 或使用 Glide/Picasso 的任何地方的最佳方式

标签: android arrays android-internet


【解决方案1】:

你只需要存储图片的url。

ArrayList<String> imagesFromURL = new ArrayList<String>();
//then do a loop over you urls and
imagesFromURL.add("some url here");

【讨论】:

    【解决方案2】:

    我是 android 新手,通过一些网上冲浪我想出了这个答案。制作一个位图数组以从 url 获取图像,然后在任何需要的地方使用它,从这个链接 [Load image from url

    Bitmap[] mThumbIds =new Bitmap[10];//for exapmle 10
    URL url = new URL("Your URL");//image url is stored here
    mThumbIds[0]= BitmapFactory.decodeStream(url.openConnection().getInputStream());//this line help to get the image(for given url) and store it in BitMapArray
    

    使用上述数组在图像视图中显示它

    imageView.setImageBitmap(mThumbIds[0]);
    

    【讨论】:

      【解决方案3】:

      做这样的事情:

      ArrayList<Bitmap> imagesList= new ArrayList<Bitmap>();
      //loop and download image and put it in this list
      imagesList.add(bitmap);
      

      【讨论】:

        【解决方案4】:

        只需先从http://square.github.io/picasso/下载Lib

        然后Picasso.with(context).load("your url of img").into(imageView);

        【讨论】:

          猜你喜欢
          • 2019-05-07
          • 2020-02-12
          • 2016-08-16
          • 2019-07-24
          • 1970-01-01
          • 2014-05-25
          • 2022-09-27
          • 1970-01-01
          • 2015-07-06
          相关资源
          最近更新 更多