java - How do I get a bitmap from AsyncTask and set it to my image -
i trying use asynctask convert image url bitmap in order set image. don't understand how bitmap out of asynctask can set images creating in loop. have tried set bitmap image inside asynctask. understanding must done inside asynctask unable reference images want set value for.
i have researched url bitmap conversion , asynctask can't figure out how combine them want. has common task. why difficult?
how reference images in asynctask?
can return bitmap , set image outside of asynctask?
is there easier way set url image source?
i have included have far.
thank , taking time read this.
class bitmaptaks extends asynctask<string, void, bitmap> { public bitmap doinbackground(string... urls) { bitmap bm = null; try { url aurl = new url(urls[0]); urlconnection conn = aurl.openconnection(); conn.connect(); inputstream = conn.getinputstream(); bufferedinputstream bis = new bufferedinputstream(is); bm = bitmapfactory.decodestream(bis); bis.close(); is.close(); } catch (ioexception e) { log.e("img", "error getting bitmap", e); } return bm; } protected void onpostexecute(bitmap bm) { //do after execute } }
this has common task. why difficult?
i'd recommend take android volley library. it's made abstract away asynctask boilerplate code. here's nice example of how set image bitmap
imageloader imageloader = appcontroller.getinstance().getimageloader(); // if using normal imageview imageloader.get(const.url_image, new imagelistener() { @override public void onerrorresponse(volleyerror error) { log.e(tag, "image load error: " + error.getmessage()); } @override public void onresponse(imagecontainer response, boolean arg1) { if (response.getbitmap() != null) { // load image imageview imageview.setimagebitmap(response.getbitmap()); } } });
you can read more here: http://www.androidhive.info/2014/05/android-working-with-volley-library-1/
Comments
Post a Comment