php - I am trying to display an image through bitmap by fetching it from phpMyAdmin. But the image is not getting displayed -
i trying display image through bitmap fetching mysql image not getting displayed. i've tried lot couldn't thing. here php code:
<?php $mysqli = new mysqli('localhost', 'root', '', 'demo'); if (mysqli_connect_error()) { die('connect error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } if($_server['request_method']=='get'){ $id = $_get['id']; $sql = "select * output_images imageid='$id'"; $r = mysqli_query($mysqli,$sql); $result = mysqli_fetch_array($r); header('content-type: image/jpeg'); echo base64_decode($result['imagedata']); mysqli_close($mysqli); }else{ echo "error"; } ?>
here android code fetches imagedata
table , displays through bitmap.
public class testmainactivity extends activity implements onclicklistener { edittext enterid; button fetchimage; imageview img; @override protected void oncreate(bundle savedinstancestate) { strictmode.enabledefaults(); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_test_main); enterid = (edittext)findviewbyid(r.id.edittext1); fetchimage = (button) findviewbyid(r.id.button1); img = (imageview)findviewbyid(r.id.imageview1); fetchimage.setonclicklistener(this); } private void getimage() { // todo auto-generated method stub class getimage extends asynctask<string,void,bitmap> { protected void onpreexecute(){ } protected bitmap doinbackground(string...params){ string id = params[0]; string url1 = "http://12.0.0.1/demo_d/getimage.php?imageid="+id; bitmap image = null; try{ url url = new url(url1); image = bitmapfactory.decodestream(url.openconnection().getinputstream()); } catch(exception e){ toast.maketext(getapplicationcontext(), (charsequence) e, toast.length_long).show(); } return image; } protected void onpostexecute(bitmap image){ super.onpostexecute(image); img.setimagebitmap(image); } } string id1 = enterid.gettext().tostring(); getimage =new getimage(); i.execute(id1); } @override public void onclick(view arg0) { // todo auto-generated method stub getimage(); } }
after execution of code found no errors there imageview
blank , required image not been displayed.
looks trying use machine while running code on android emulator because using ip 127.0.0.1
.
if use 127.0.0.1
on emulator points itself.
to access host machine emulator should use http://10.0.2.2:8080
.
so, url should this
string url1 = "http://10.0.2.2:8080/demo_d/getimage.php?imageid="+id;
see this more information on matter.
Comments
Post a Comment