Android, How to retrieve the image previously save and display when required -
i used code below save image taken camera intent, folder in gallery, worked great. i'd retrieve image display on imageview within activity when asked, though after trying various methods/code, nothing far has worked. given path/code used save image, point me in right direction of how back. in advance - jim.
public void saveimage(context context,bitmap imagetosave, string filename){ thethis = context; string file_path = environment.getexternalstoragedirectory()+ nameoffolder; // string currentdateandtime= getcurrentdateandtime(); file dir = new file(file_path); if(!dir.exists()){ dir.mkdirs(); } file file = new file(dir, filename + ".jpg"); try { fileoutputstream fout = new fileoutputstream(file); imagetosave.compress(bitmap.compressformat.jpeg, 100, fout); fout.flush(); fout.close(); makesurefilewascreatedthenmakeavabile(file); abletosave(); } catch (filenotfoundexception e) {unabletosave();} catch (ioexception e){unabletosave();} } private void makesurefilewascreatedthenmakeavabile(file file) { mediascannerconnection.scanfile(thethis, new string[] { file.tostring() }, null, new mediascannerconnection.onscancompletedlistener() { public void onscancompleted(string path, uri uri) { log.e("externalstorage", "scanned " + path + ":"); log.e("externalstorage", "-> uri=" + uri); } }); }
if have proper path , permissions, here code working me
file rootsd = environment.getexternalstoragedirectory(); string rootpath = rootsd.getabsolutepath(); string pathname = rootpath + "your path here" + "image name here"; try { drawable d = drawable.createfrompath(pathname); layout.setbackgrounddrawable(d); } catch (exception e) { e.printstacktrace(); } hope helps , enjoy work.
Comments
Post a Comment