0

how to fetch the image stored in mysql on server? I want to fetch those images based on the values user has entered (means dynamic query). I want to use json to send the image from php to android. I successfully displayed that image in web browser using static query but when I saw the response of the php in android app it shows some html code instead of image.please help me in parsing the image json response and displaying that image. following is the php code to send image to android.

 while($post = mysql_fetch_object($data))
 {
    $posts[] = $post;

 }
         //header("Content-type: image/jpeg");

         echo '{"pprs":'.json_encode($posts).'}'; 

now i am getting response : {"pprs":[{"pprs":null},{"pprs":null}]}

please help me.Thank you.

7
  • you have to show the response in order for us to parse it. Commented Sep 28, 2012 at 21:12
  • Do you have any sample code or anything? Without any more details, it's very difficult as to what may be happening. Commented Sep 28, 2012 at 22:48
  • I am getting the following response 2{"pprs":null}{"pprs":null} Commented Sep 29, 2012 at 19:38
  • 2 are the number of rows fetched from db but it shows null. Commented Sep 29, 2012 at 19:39
  • currently i am trying static sql query to retrieve all the images from mysql. As shown in the code above $data contains query result. Commented Sep 29, 2012 at 20:51

1 Answer 1

2

You need to convert your image to string if you want to use JSON:

    $posts[] = base64_encode($post);

And on Android side:

String base64image = jsonobject.getString("pprs");
byte[] rawImage = Base64.decode(base64image, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
ImageView imageview = (ImageView) findViewById(R.id.imgPicture);
imageview.setImageBitmap(bmp);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.