从JSON下载图像

时间:2015-11-14 13:10:13

标签: c# android json xamarin

我在[img_url]字段中的Json中有图片网址。

我需要在ParseandDisplay方法

中下载它

ParseAndDisplay:

private void ParseAndDisplay1(JsonValue json)
        {


            //ImageButton product = FindViewById<ImageButton>(Resource.Id.vugor);
            TextView productname = FindViewById<TextView>(Resource.Id.posttittle);
            TextView price = FindViewById<TextView>(Resource.Id.price);
            TextView weight = FindViewById<TextView>(Resource.Id.weight);
            productname.Click += delegate
            {
            var intent485 = new Intent(this, typeof(GoryachieRolli1));
                StartActivity(intent485);
            };
            JsonValue firstitem = json[1];
            //Console.Out.WriteLine(firstitem["post_title"].ToString());
            productname.Text = firstitem["post_title"];
            price.Text = firstitem["price"] + " грн";
            weight.Text = firstitem["weight"] + "г";


        }

我现在如何下载图片:

private Bitmap GetImageBitmapFromUrl1(string url)
        {
            Bitmap imageBitmap = null;

            using (var webClient = new WebClient())
            {
                var imageBytes = webClient.DownloadData(url);
                if (imageBytes != null && imageBytes.Length > 0)
                {
                    imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                }
            }

            return imageBitmap;
        }

我需要在解析和显示中进行下载和显示

1 个答案:

答案 0 :(得分:0)

只需添加对GetImageBitmapFromUrl1()方法的调用

wallNode.physicsBody!.dynamic = false