How to download image file with unknown length on android -
i'm trying display file local network url
http://192.168.1.118:1881/image.jpg
and display immidiatelly in imageview. problem when open inputstream url , try decode bitmapfactory null bitmap. suppose because message input stream: libcore.net.http.unknownlengthhttpinputstream.
that image supported , hosted server app can't modify.
thanks much, i've tried hard , looked solutions, nothing works me
download byte array , decode byte array:
byte[] data = read(inputstreamfromconnection); if (data != null) { bitmap downloadedbitmap = bitmapfactory.decodebytearray(data, 0, data.length); } public static byte[] read(inputstream is) { bytearrayoutputstream baos = new bytearrayoutputstream(8192); try { // read buffer, read big chunk @ time. byte[] buf = new byte[2048]; int len; // read until -1 returned, i.e. stream ended. while ((len = is.read(buf)) != -1) { baos.write(buf, 0, len); } } catch (ioexception e) { log.e("downloader", "file not downloaded", e); } { try { is.close(); } catch (ioexception e) { // input stream not closed. } } return baos.tobytearray(); }
Comments
Post a Comment