java - How to show a php image in imageview? -
i trying code , it's not working. how can download pic , show it.
my java code
private imageview iv; private bitmap bitmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_showprofile); iv = (imageview) findviewbyid(r.id.virus); bitmap = getbitmapfromurl("http://getbloodbd.org/image.php?no=4"); iv.setimagebitmap(bitmap);} public bitmap getbitmapfromurl(string src) { try { url url = new url(src); httpurlconnection connection = (httpurlconnection) url .openconnection(); connection.setdoinput(true); connection.connect(); inputstream input = connection.getinputstream(); bitmap mybitmap = bitmapfactory.decodestream(input); return mybitmap; } catch (exception e) { // todo: handle exception e.printstacktrace(); return null; } }
and xml code
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="org.getbloodbd.getbloodbd.showprofileactivity" tools:showin="@layout/app_bar_showprofile"> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <imageview android:id="@+id/virus" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentend="true" android:layout_alignparentstart="true" /> </relativelayout>
and php code , in webview method it's work fine, image view not working, need image view method .
<?php include 'config.php';header("content-type: image/gif" );$no=$_get['no']; $dn = mysql_query('select image images no="'.$no.'"'); $dnn = mysql_fetch_array($dn); $data = $dnn['image'];echo base64_decode($data);?>
how solve ?
you can load image url below
url url = new url("image full path"); bitmap bmp = bitmapfactory.decodestream(url.openconnection().getinputstream()); imageview.setimagebitmap(bmp);
another way load image
private bitmap bmp; new asynctask<void, void, void>() { @override protected void doinbackground(void... params) { try { inputstream in = new url(image_url).openstream(); bmp = bitmapfactory.decodestream(in); } catch (exception e) { // log error } return null; } @override protected void onpostexecute(void result) { if (bmp != null) imageview.setimagebitmap(bmp); } }.execute();
please reference here. please have try
Comments
Post a Comment