android - different getPath for different images -


i need set different getpath() different images . below sample describing getpath 1 image . not able understand how use setting 2 images .

public string getpath(uri uri) {         string[] projection = { mediastore.images.media.data };         cursor cursor = managedquery(uri, projection, null, null, null);         if (cursor != null) {             // here nullpointer if cursor null             // can be, if used oi file manager picking media             int column_index = cursor                     .getcolumnindexorthrow(mediastore.images.media.data);             cursor.movetofirst();             return cursor.getstring(column_index);         } else             return null;     } 

bitmap :-

public void decodefile(string filepath) {         // decode image size         bitmapfactory.options o = new bitmapfactory.options();         o.injustdecodebounds = true;         bitmapfactory.decodefile(filepath, o);          // new size want scale         final int required_size = 70;          // find correct scale value. should power of 2.         int width_tmp = o.outwidth, height_tmp = o.outheight;         int scale = 1;         while (true) {             if (width_tmp < required_size && height_tmp < required_size)                 break;             width_tmp /= 2;             height_tmp /= 2;             scale *= 2;         }          // decode insamplesize         bitmapfactory.options o2 = new bitmapfactory.options();         o2.insamplesize = scale;         bitmap = bitmapfactory.decodefile(filepath, o2);         bitmap2 = bitmapfactory.decodefile(filepath, o2);         imgview.setimagebitmap(bitmap);          imgview2.setimagebitmap(bitmap2); 

no not have use different getpath multiple images, can have single method n number of images,

look @ below example,

//button's click event openong phone's gallery

but1.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 opengallery(select_file1);             }         });          but2.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 opengallery(select_file2);             }         }); 

where here open gallery function.

public void opengallery(int req_code) {         intent = new intent(intent.action_pick,                 android.provider.mediastore.images.media.internal_content_uri);         startactivityforresult(i, req_code);     } 

and inside onactivity result setting different path which images,

public void onactivityresult(int requestcode, int resultcode, intent data) {          if (resultcode == result_ok) {             uri selectedimageuri = data.getdata();              if (requestcode == select_file1) {                 selectedpath1 = getpath(selectedimageuri);                 edittext1.settext(selectedpath1);             }             if (requestcode == select_file2) {                 selectedpath2 = getpath(selectedimageuri);                 edittext2.settext(selectedpath2);             }          }     } 

and here @ last

public string getpath(uri uri) {         string[] projection = { mediastore.images.media.data };         @suppresswarnings("deprecation")         cursor cursor = managedquery(uri, projection, null, null, null);         int column_index = cursor                 .getcolumnindexorthrow(mediastore.images.media.data);         cursor.movetofirst();         return cursor.getstring(column_index);     } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -