android - Picking image always gives landscape image -


i have used following code pick image phone's gallery:

intent intent = new intent();   intent.settype("image/*");   intent.setaction(intent.action_get_content);   startactivityforresult(intent.createchooser(intent, "select picture"),     use_library_pic_request); 

in onactivityresult(), gives filepath, tried getting bitmap using filepath, gives in landscape view. there way image in portrait view always? code getting filepath:

uri selectedimageuri = data.getdata();     selectedimagepath = getpath(selectedimageuri); 

this how got bitmap using file path:

bitmap bmp=bitmapfactory.decodefile(selectedimagepath); 

to original image can use method.

public static bitmap getbitmap(string uri, context mcontext) {      bitmap bitmap = null;     uri actualuri = uri.parse(uri);     bitmapfactory.options options = new bitmapfactory.options();     options.intempstorage = new byte[16 * 1024];     options.insamplesize = 2;     contentresolver cr = mcontext.getcontentresolver();     float degree = 0;     try {         exifinterface exif = new exifinterface(actualuri.getpath());         string exiforientation = exif                 .getattribute(exifinterface.tag_orientation);         bitmap = bitmapfactory.decodestream(cr.openinputstream(actualuri),                 null, options);         if (bitmap != null) {             degree = getdegree(exiforientation);             if (degree != 0)                 bitmap = createrotatedbitmap(bitmap, degree);         }     } catch (filenotfoundexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }     return bitmap; }  public static float getdegree(string exiforientation) {     float degree = 0;     if (exiforientation.equals("6"))         degree = 90;     else if (exiforientation.equals("3"))         degree = 180;     else if (exiforientation.equals("8"))         degree = 270;     return degree; }  public static bitmap createrotatedbitmap(bitmap bm, float degree) {     bitmap bitmap = null;     if (degree != 0) {         matrix matrix = new matrix();         matrix.prerotate(degree);         bitmap = bitmap.createbitmap(bm, 0, 0, bm.getwidth(),                 bm.getheight(), matrix, true);     }      return bitmap; } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -