Reputation: 821
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.
Upvotes: 0
Views: 1708
Reputation: 801
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);
Upvotes: 2