title: How to show image on imageview using webservices and json
body: <p>I am using web service for showing image in imageview. But web service image show in SYSTEM.BYTE[] Format. So how to Convert or display the image in imageview in xamarin android application??    </p>
  
  <p><strong>Webservice.asmx:</strong></p>
  
  <pre><code>[WebMethod(MessageName = "BindHospName", Description = "Bind Hospital Name Control")]
      [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
      [System.Xml.Serialization.XmlInclude(typeof(GetHospName))]
      public string BindHosp(decimal SpecID)
      {
          JavaScriptSerializer objJss = new JavaScriptSerializer();
          List&lt;GetHospName&gt; HospName = new List&lt;GetHospName&gt;();
          try
          {
              ConnectionString();
              cmd = new SqlCommand("select b.HID,b.HospName,b.Logo from HospitalRegBasic b inner join HospitalRegClinical c on b.HID=c.HID " +
                                   "where b.EmailActivationCode &lt;&gt; '' and b.EmailActivationStatus = 1 and b.Status = 1 and c.SPEC_ID = @SpecID ", conn);
              cmd.Parameters.AddWithValue("@SpecID", SpecID);
              dr = cmd.ExecuteReader();
              if (dr.HasRows)
              {
                  while (dr.Read())
                  {
                      var getHosp = new GetHospName
                      {
                          HospID = dr["HID"].ToString(),
                          HospName = dr["HospName"].ToString(),
                          HospLogo = dr["Logo"].ToString()
                      };
  
                      HospName.Add(getHosp);
                  }
              }
              dr.Close();
              cmd.Dispose();
              conn.Close();
          }
          catch (Exception)
          {
              throw;
          }
          return objJss.Serialize(HospName);
      }
  </code></pre>
  
  <p><strong>Class.cs:</strong>       </p>
  
  <pre><code>namespace HSAPP
  {
      class ContListViewHospNameClass : BaseAdapter&lt;GetHospNames&gt;
      {
          List&lt;GetHospNames&gt; objList;
  
          Activity objActivity;
  
          public ContListViewHospNameClass (Activity objMyAct, List&lt;GetHospNames&gt; objMyList) : base()
          {
              this.objActivity = objMyAct;
              this.objList = objMyList;
          }
  
          public override GetHospNames this[int position]
          {
              get
              {
                  return objList[position];
              }
          }
  
          public override int Count
          {
              get
              {
                  return objList.Count;
              }
          }
  
          public override long GetItemId(int position)
          {
              return position;
          }
  
          public static Bitmap bytesToBitmap(byte[] imageBytes)
          {
  
              Bitmap bitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
  
              return bitmap;
          }
  
          public override View GetView(int position, View convertView, ViewGroup parent)
          {
              var item = objList[position];
  
              if (convertView == null)
              {
                  convertView = objActivity.LayoutInflater.Inflate(Resource.Layout.ContListViewHospName, null);
              }
              convertView.FindViewById&lt;TextView&gt;(Resource.Id.tvHospID).Text = item.HospID;
              convertView.FindViewById&lt;TextView&gt;(Resource.Id.tvHospName).Text = item.HospName;
  
              byte[] img =item.HospLogo;
  
              Bitmap bitmap = BitmapFactory.DecodeByteArray(img, 0, img.Length);
  
              convertView.FindViewById&lt;ImageView&gt;(Resource.Id.imgLogo).SetImageBitmap(bitmap);
              return convertView;
          }
      }
  }
  </code></pre>
  
  <p><strong>This is JSON Code:</strong>     </p>
  
  <pre><code>private void BindControl_BindHospCompleted(object sender, BindControl.BindHospCompletedEventArgs e)
  {
      jsonValue = e.Result.ToString();
  
      if (jsonValue == null)
      {
          Toast.MakeText(this, "No Data For Bind", ToastLength.Long).Show();
          return;
      }
  
      try
      {
          JArrayValue = JArray.Parse(jsonValue);
          list = new List&lt;GetHospNames&gt;();
          int count = 0;
          while (count &lt; JArrayValue.Count)
          {
  
              GetHospNames getHospName = new GetHospNames(JArrayValue[count]["HospID"].ToString(), JArrayValue[count]["HospName"].ToString(),JArrayValue[count]["Logo"]);
              list.Add(getHospName);
              count++;
          }
          listView.Adapter = new ContListViewHospNameClass(this, list);
      }
      catch (Exception ex)
      {
          Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
      }
  }
  </code></pre>