java - Store the taken picture from ImageView to the phone storage -
after take picture store picture imageview, if has idea or suggestion in how store picture after shown on imageview phone stage without user interaction in advance
public class mainactivity extends activity { imageview viewpict; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); viewpict=(imageview) findviewbyid(r.id.pict_result); button btn= (button)findviewbyid(r.id.camera); btn.setonclicklistener(new onclicklistener(){ @override public void onclick(view arg0) { intent intent = new intent (android.provider.mediastore.action_image_capture); // intent intent = new intent (getapplicationcontext(),mainactivity2.class); //startactivity(intent); startactivityforresult(intent,0); } }); } protected void onactivityresult( int requestcode, int resultcode,intent data) { if (requestcode==0) { bitmap theimage = (bitmap) data.getextras().get("data"); viewpict.setimagebitmap(theimage); } } }
try:
viewpict.builddrawingcache(); bitmap bm=viewpict.getdrawingcache();
and save:
outputstream fout = null; uri outputfileuri; try { file root = new file(environment.getexternalstoragedirectory() + file.separator + "folder_name" + file.separator); root.mkdirs(); file sdimagemaindirectory = new file(root, "mypicname.jpg"); outputfileuri = uri.fromfile(sdimagemaindirectory); fout = new fileoutputstream(sdimagemaindirectory); } catch (exception e) { toast.maketext(this, "error occured. please try again later.", toast.length_short).show(); } try { bm.compress(bitmap.compressformat.png, 100, fout); fout.flush(); fout.close(); } catch (exception e) { }
and permission in androidmanifest:
<uses-permission android:name="android.permission.write_external_storage" />
Comments
Post a Comment