如何在数组中存储URL中的图像

时间:2014-08-07 18:19:05

标签: android arrays android-internet

我想将图片存储在网址中,但我不知道如何实现此功能。

就像我从数组中的drawable存储图像一样,我希望将数据存储在URL中。

drawable的例子:

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

    };

4 个答案:

答案 0 :(得分:1)

首先从http://square.github.io/picasso/

下载Lib

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

答案 1 :(得分:0)

您只需要存储图片的网址。

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

答案 2 :(得分:0)

我是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中显示它

imageView.setImageBitmap(mThumbIds[0]);

答案 3 :(得分:0)

做这样的事情:

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