i have save button imageview bitmap picture. when click it, 3 copies of same image, 2 of them 0 bytes. here's image:

and here's code:
public class photo_gallery extends activity implements onclicklistener{ button save; imageview slika; final file mydir = new file("/sdcard/pictures/sexyimages"); boolean success = false; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.photo_gallery); initializevars(); } private void initializevars() { slika = (imageview) findviewbyid(r.id.imageview1); save = (button) findviewbyid(r.id.bsave); save.setonclicklistener(new onclicklistener() { public void onclick(view v) { final random generator = new random(); int n = 10000; n = generator.nextint(n); final string fname = "styleme-" + n + ".png"; mydir.mkdirs(); file image = new file(mydir, fname); bitmapdrawable drawable = (bitmapdrawable) slika.getdrawable(); bitmap bitmap = drawable.getbitmap(); // encode file png image. fileoutputstream outstream; try { outstream = new fileoutputstream(image); bitmap.compress(bitmap.compressformat.png, 100, outstream); /* 100 keep full quality of image */ outstream.flush(); outstream.close(); success = true; } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } if (success) { toast.maketext(getapplicationcontext(), "image saved success @ /sdcard/pictures/sexyimages", toast.length_long).show(); } else { toast.maketext(getapplicationcontext(), "error during image saving", toast.length_long).show(); } } }); } and second queston....how refresh gallery app? know have implement code somewhere, don't know how:
environment.getexternalstoragedirectory();
Comments
Post a Comment