android - Save image to phone loaded from gallery -


i'm trying save image loaded gallery phone memory(local path). can guide me this?

this how image gallery.

imageview profilepicture; private uri imageuri; string picturepath;  @override public void oncreate(bundle savedinstancestate)   {      profilepicture = (imageview) findviewbyid(r.id.profile_picture);         profilepicture.setontouchlistener(new ontouchlistener() {             @override             public boolean ontouch(view arg0, motionevent arg1) {                 switch (arg1.getaction()) {                 case motionevent.action_down: {                     break;                 }                 case motionevent.action_up:{                     uploadimage();                     break;                 }                 }                 return true;             }         }); } 

uploadimage()

intent galleryintent = new intent(intent.action_pick,     android.provider.mediastore.images.media.external_content_uri);   startactivityforresult(galleryintent, 1);  @override public void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         switch (requestcode) {         case 0:             if (resultcode == activity.result_ok) {                 uri selectedimage = imageuri;                 getcontentresolver().notifychange(selectedimage, null);                 contentresolver cr = getcontentresolver();                 bitmap bitmap;                 try {                      bitmap = android.provider.mediastore.images.media                      .getbitmap(cr, selectedimage);                       profilepicture.setimagebitmap(bitmap);                 } catch (exception e) {                     toast.maketext(this, "failed load", toast.length_short)                             .show();                     log.e("camera", e.tostring());                 }             }         case 1:              if (resultcode == activity.result_ok && null != data) {                  uri selectedimage = data.getdata();                  string[] filepathcolumn = { mediastore.images.media.data };                   cursor cursor = getcontentresolver().query(selectedimage,                          filepathcolumn, null, null, null);                  cursor.movetofirst();                   int columnindex = cursor.getcolumnindex(filepathcolumn[0]);                  picturepath = cursor.getstring(columnindex);                  cursor.close();                  profilepicture.setbackgroundcolor(color.transparent);                      profilepicture.setimagebitmap(bitmapfactory.decodefile(picturepath));               }          }     } 

*note: case 0 image capturing using phones camera.

i can display on imageview need store in phone's memory everytime open app, able load previous uploaded image image view. if user wants upload again. file saved overwritten. don't want result storing images blob using sqlite since uploading 1 image whole app. want store in local file path myappname/images/image.png. ideas? thanks!

you can store image in application cache directory such as:

try {     string destfolder = getcachedir().getabsolutepath()+ "/images/";         if (!new file(destfolder).exists()) {             new file(destfolder).mkdirs();         }          fileoutputstream out = new fileoutputstream(destfolder + "profile.png");             bitmap.compress(bitmap.compressformat.png, 100, out);         out.close(); } catch (exception ex) {     ex.printstacktrace();                } 

and read file bitamp:

string fname = "profile.png"; bitmap profile = bitmapfactory.decodefile(getcachedir().getabsolutepath()+ "/images/"  + fname); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -