title: Displaying Image from PHP MySQL into imageview in Android using Json
body: <p>I'm trying  to display an image into imageview in android from php mysql..I'm using JSON to parse the image..  </p>
  
  <pre><code> nom | couleur | image  
   -------------------------------------------------------------------  
   passat | gris |http://10.0.2.2/model/image/passat.jpg  
  </code></pre>
  
  <p>My php code:  </p>
  
  <pre><code>$result = mysql_query("SELECT * FROM info WHERE nom = '$nom'");  
  
  if (!empty($result)) {  
      // check for empty result  
      if (mysql_num_rows($result) &gt; 0) {  
  
          $result = mysql_fetch_array($result);  
  
          $info = array();  
  
          $info["nom"] = $result["nom"];  
          $info["couleur"] = $result["couleur"];  
          $info["prix"] = $result["prix"];  
          $info["image"] = base64_encode($result["image"]);  
          // success  
          $response["success"] = 1;  
  
          // user node  
          $response["info"] = array();  
  
          array_push($response["info"], $info);  
  
          // echoing JSON response  
          echo json_encode($response); 
  
      }
  }
  </code></pre>
  
  <p>and here is my Info.java code:  </p>
  
  <pre><code>package com.example.gridview2;  
  
  import java.util.ArrayList;  
  import java.util.List;  
  
  import org.apache.http.NameValuePair;  
  import org.apache.http.message.BasicNameValuePair;  
  import org.json.JSONArray;  
  import org.json.JSONException;  
  import org.json.JSONObject;  
  
  import android.app.Activity;  
  import android.content.Intent;  
  import android.graphics.Bitmap;  
  import android.graphics.BitmapFactory;  
  import android.os.Bundle;  
  import android.util.Base64;  
  import android.util.Log;  
  import android.widget.ImageView;  
  import android.widget.TextView;  
  
  public class Info extends Activity {
  
      TextView txt1,txt2,txt3;  
      ImageView image;  
      JSONParser jParser = new JSONParser();  
      private static final String url_product_detials = "http://10.0.2.2/model/detail.php";  
      private static final String TAG_SUCCESS = "success";  
      private static final String TAG_PRODUCT = "info";  
      private static final String TAG_NAME = "nom";  
      private static final String TAG_COLOR = "couleur";  
      private static final String TAG_PRICE = "prix";  
      private static final String TAG_IMAGE = "image";  
  
      public void onCreate(Bundle savedInstanceState) {  
          super.onCreate(savedInstanceState);  
          setContentView(R.layout.main7);  
  
          process();  
      }
      private void process() {  
          Intent intent = getIntent();  
          String nom = intent.getStringExtra(TAG_NAME);  
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();  
          params.add(new BasicNameValuePair(TAG_NAME, nom));  
          JSONObject json = jParser.makeHttpRequest(url_product_detials, "GET",
                  params);  
          Log.d("Single employee Details", json.toString());  
          try {  
  
              int success = json.getInt(TAG_SUCCESS);  
  
              if (success == 1) {  
                  JSONArray productObj = json.getJSONArray(TAG_PRODUCT); // JSON Array  
  
                  // get first product object from JSON Array  
                  JSONObject product = productObj.getJSONObject(0);  
  
                  txt1 = (TextView) findViewById(R.id.textView1);  
                  txt2 = (TextView) findViewById(R.id.textView2);  
                  txt3 = (TextView) findViewById(R.id.textView3);  
                  image = (ImageView) findViewById(R.id.imageView1);  
  
                  String NOM =product.getString(TAG_NAME);  
                  String couleur = product.getString(TAG_COLOR);  
                  String prix =   product.getString(TAG_PRICE);  
                  String image1 =   product.getString(TAG_IMAGE);  
                  txt1.setText(NOM);  
                  txt2.setText(couleur);  
                  txt3.setText(prix);  
                  byte[] encodeByte = Base64.decode(image1, Base64.DEFAULT);  
                  Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);       
  
                  image.setImageBitmap(bitmap);  
  
              } else{  
                  // product with pid not found
              }  
          } catch (JSONException e) {  
              e.printStackTrace();  
          }  
      }  
  }
  </code></pre>
  
  <p>my json response:  </p>
  
  <pre><code>{
    "success": 1,
    "info": [
      {
        "nom": "passat",
        "couleur": "gris",
        "prix": "1000",
        "image": "aHR0cDovLzEwLjAuMi4yL21vZGVsL2ltYWdlL3Bhc3NhdC5qcGc="
      }
    ]
  }
  </code></pre>
  
  <p>image doesn't show , i don't know where is the problem<br>
  can any one help me  </p>