android - How to get Bitmap from an Uri? -
how bitmap object uri (if succeed store in /data/data/myfolder/myimage.png
or file///data/data/myfolder/myimage.png
) use in application?
does have idea on how accomplish this?
. . important: see answer @mark ingram below , @pjv @ better solution. . .
you try this:
public bitmap loadbitmap(string url) { bitmap bm = null; inputstream = null; bufferedinputstream bis = null; try { urlconnection conn = new url(url).openconnection(); conn.connect(); = conn.getinputstream(); bis = new bufferedinputstream(is, 8192); bm = bitmapfactory.decodestream(bis); } catch (exception e) { e.printstacktrace(); } { if (bis != null) { try { bis.close(); } catch (ioexception e) { e.printstacktrace(); } } if (is != null) { try { is.close(); } catch (ioexception e) { e.printstacktrace(); } } } return bm; }
but remember, method should called within thread (not gui -thread). asynctask.
Comments
Post a Comment