good day internet!
i trying retrieve , display image mysql database image view (android). image blob type. have following php code gets image mysql.
<?php error_reporting(e_all ^ e_deprecated); require 'connect_aircraftoperator.php'; $image = $db->query("select * company"); while ($row = $image->fetch_assoc()) { echo '<img src="data:image/png;base64,' . base64_encode($row['companyimage']) . '" />'; } ?>
below android code use of json.
try { //setting default http client httpclient httpclient = new defaulthttpclient(); //specify url , name of php file going use //as parameter httppost method httppost httppost = new httppost("http://10.0.2.2//aircraftoperatorapp/leimage.php"); httppost.setentity(new urlencodedformentity(namevaluepairs)); //getting response httpresponse response = httpclient.execute(httppost); //setting entity httpentity httpentity = response.getentity(); //setting content inside input stream reader //lets define input stream reader = httpentity.getcontent(); } catch (exception e) { system.out.println("exception 1 caught "); } try { bufferedreader reader = new bufferedreader(new inputstreamreader(is, "iso-8859-1"), 8); //create string builder object hold data stringbuilder sb = new stringbuilder(); string line = null; while ((line = reader.readline()) != null) { sb.append(line+"\n"); } //use tostring() method data in result fullnameresult = sb.tostring(); is.close(); //checks data printing result in logcat system.out.println("---here's data---"); system.out.println(fullnameresult); } catch (exception e){ system.out.println("exception 2 caught "); } //result contains data in form of json //let's inflate in form of list try { //creates json array jsonarray jarray = new jsonarray(fullnameresult); (int = 0; < jarray.length(); i++) { //create json object extract data jsonobject json_data = jarray.getjsonobject(i); imagetemp = json_data.getstring("companyimage"); //gets value php } //this line should display image mysql database image view } catch (exception e){ //system.out.println("exception 3 caught "); log.e("lag_tag", "error parsing data " + e.tostring()); }
thanks in advance help!
first use base64 decode string byte array:
byte[] data = base64.decode(imagetemp); bitmap b = bitmapfactory.decodebytearray(data,0,data.length,null);