如何从webService,Android创建图像

时间:2017-03-09 12:00:27

标签: java android json imageurl

所以,我有这个连接到WebService的应用程序,我已经从那里检索数据,现在我想要检索图像链接并使imageView通过链接获取该图像。这甚至可能吗?感谢任何帮助:D

if-then

6 个答案:

答案 0 :(得分:1)

您可以使用Picasso,一个精彩的图片库。

示例:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

通过Gradle添加依赖项:

compile 'com.squareup.picasso:picasso:2.5.2'

答案 1 :(得分:0)

您可以使用任何第三方库 示例使用Glide

此库可帮助您从ImageView获取并显示url上的图片。

示例:

Glide.with(context).load(image_url).into(your_image_view);

这是该库的链接:https://github.com/bumptech/glide

答案 2 :(得分:0)

您必须像平常一样在XML中设置ImageView。然后,您可以使用任何第三方库,例如PicassoGlide,它们会从网址加载图片并将其设置为您的活动/片段中的ImageView。

答案 3 :(得分:0)

在你的app build.gradle中添加

compile 'com.github.bumptech.glide:glide:3.7.0'

使用此代码从网址加载图片

 Glide.with(getApplicationContext()).load("image_url").into(ImageView);

答案 4 :(得分:0)

如果您不想使用第三方库,请尝试此操作

 new DownloadImage(imamgeview).execute(url);

创建异步任务

 public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
    CircleImageView bmImage;

    public DownloadImage(ImageView bmImage) {
        this.bmImage = (CircleImageView) bmImage;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.d("Error", e.getStackTrace().toString());

        }
        return mIcon11;
    }

    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
}

我希望你能在你的案例中发挥作用

答案 5 :(得分:0)

第1步:创建名为DownloadImage的类

exports

第2步:执行AsyncTask

declarations

** Json Url是这样的:** https://graph.facebook.com/1220130444748799/picture?height=400&width=400&migration_overrides=%7Boctober_2012%3Atrue%7D