android - Saving image from httpResponce -
i have download image httpresponse
, save on internal storage on android device. have block of code trying that:
httpresponse httpresponse = httpclient.execute(httppost); inputstream inputstream = httpresponse.getentity().getcontent(); bitmap logo = bitmapfactory.decodestream(inputstream); fileoutputstream fos = null; try { fos = getapplicationcontext().openfileoutput("logo.png",context.mode_private); logo.compress(bitmap.compressformat.png, 90, fos); } catch (filenotfoundexception e) { e.printstacktrace(); } { fos.close(); }
but dont result need. saved image not open image viewvers , slighly bigger in size too. image download 1.71 kb , result 2.01 kb. ideas?
i don't know what's real problem in code can try code if want,this code ran without problem me
to save internal memory...
file filewithinmydir = getapplicationcontext().getfilesdir(); try { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder() .permitall().build(); strictmode.setthreadpolicy(policy); url url = new url("http://t2.gstatic.com /images?q=tbn:and9gcqjzguffqqe2mkkb5vordnd-zxd7sjou7wahlfay6plbtxpyqzydw"); file file = new file( filewithinmydir.getabsolutepath() + "/" +"sun.jpg"); urlconnection ucon = url.openconnection(); inputstream = ucon.getinputstream(); bufferedinputstream bis = new bufferedinputstream(is); bytearraybuffer baf = new bytearraybuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } fileoutputstream fos = new fileoutputstream(file); fos.write(baf.tobytearray()); fos.close(); } catch (ioexception e) { log.e("download", e.getmessage()); }
to load image internal memory..
strictmode.threadpolicy policy = new strictmode.threadpolicy.builder() .permitall().build(); strictmode.setthreadpolicy(policy); mimgview1 = (imageview) findviewbyid(r.id.mimgview1); bitmap bitmap = bitmapfactory.decodefile(filewithinmydir.getabsolutepath() + "/" +"sunn"+".file extension"); mimgview1.setimagebitmap(bitmap);
Comments
Post a Comment