Android - How to Send Image to other activity from load Image from SD Card -
i want ask send path image other activity , show imageview
browsephoto.java
private static int pick_from_file = 1; private static int intent_image = 2; private imagebutton buttonloadimage; private imagebutton reloadphoto; private imagebutton imagedone; private imageview mimageview; private uri mimagecaptureuri; textview textimagepath; uri imageuri = null; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); overridependingtransition(r.anim.push_left_in, r.anim.hold); setcontentview(r.layout.browse); buttonloadimage = (imagebutton) findviewbyid(r.id.btnloadimage); imagedone = (imagebutton) findviewbyid(r.id.btnphotook); reloadphoto = (imagebutton) findviewbyid(r.id.btnreload); mimageview = (imageview) findviewbyid(r.id.iv_pic); textimagepath = (textview) findviewbyid(r.id.imagepath); buttonloadimage.setonclicklistener(new view.onclicklistener() { @override public void onclick(view arg0) { intent intent = new intent(); intent.settype("image/*"); intent.setaction(intent.action_get_content); startactivityforresult( intent.createchooser(intent, "complete action using"), pick_from_file); buttonloadimage.setvisibility(view.invisible); imagedone.setvisibility(view.visible); reloadphoto.setvisibility(view.visible); } }); findviewbyid(r.id.btnphotook).setonclicklistener(this); findviewbyid(r.id.btnreload).setonclicklistener(this); } public void onclick(view v) { switch (v.getid()) { case r.id.btnphotook: movetoeditphotodraweractivity(); break; case r.id.btnreload: backtobrowsephotodraweractivity(); break; default: break; } } private void movetoeditphotodraweractivity() { intent intent = new intent(); startactivityforresult(intent, intent_image); } private void backtobrowsephotodraweractivity() { intent intent = new intent(this, browsephoto.class); startactivity(intent); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (resultcode != result_ok) return; bitmap bitmap = null; string path = ""; if (requestcode == pick_from_file) { mimagecaptureuri = data.getdata(); path = getrealpathfromuri(mimagecaptureuri); if (path == null) path = mimagecaptureuri.getpath(); if (path != null) bitmap = bitmapfactory.decodefile(path); } else { path = mimagecaptureuri.getpath(); bitmap = bitmapfactory.decodefile(path); } mimageview.setimagebitmap(bitmap); textimagepath.settext(path.tostring()); if(requestcode == intent_image){ intent intent = new intent(this, editimage.class); intent.putextra("intent_image", path); startactivity(intent); } } public string getrealpathfromuri(uri contenturi) { string[] proj = { mediastore.images.media.data }; cursor cursor = managedquery(contenturi, proj, null, null, null); if (cursor == null) return null; int column_index = cursor .getcolumnindexorthrow(mediastore.images.media.data); cursor.movetofirst(); return cursor.getstring(column_index); }
editimage.java
string picturepath = getintent().getstringextra("intent_image"); imageview imageview = (imageview) findviewbyid(r.id.iv_pic); imageview.setimagebitmap(bitmapfactory.decodefile(picturepath));
screenshoot after load image sd card
![screenshoot after load image sd card][1]
and if click button correct, intent editimage
what wrong code? if me, saved time :(
remove these lines onactivityresult
if(requestcode == intent_image){ intent intent = new intent(this, editimage.class); intent.putextra("intent_image", path); startactivity(intent); }
and change movetoeditphotodraweractivity
private void movetoeditphotodraweractivity() { intent intent = new intent(this, editimage.class); intent.putextra("intent_image", path); startactivity(intent); }
Comments
Post a Comment