imageview - Why does the Image Picker in my Android app rotate automatically portrait images into landscape? -


i'm using code in android app launch camera/gallery image, , display imageview.

when user picks image landscape orientation everythings works fine, when user picks portrait image, image displayed rotated 90 degrees. can't understand why..i'm testing app on galaxy s3 android 4.3

i've noticed problems occours when picture taken phone..maybe problem s3?

this code:

    private void openimageintent() {         // camera.         system.gc();          final list<intent> cameraintents = new arraylist<intent>();         final intent captureintent = new intent(android.provider.mediastore.action_image_capture);         final packagemanager packagemanager = getpackagemanager();         final list<resolveinfo> listcam = packagemanager.queryintentactivities(captureintent, 0);         for(resolveinfo res : listcam) {             final string packagename = res.activityinfo.packagename;             final intent intent = new intent(captureintent);             intent.setcomponent(new componentname(res.activityinfo.packagename, res.activityinfo.name));             intent.setpackage(packagename);             cameraintents.add(intent);         }          // filesystem.         final intent galleryintent = new intent();         galleryintent.settype("image/*");         galleryintent.setaction(intent.action_get_content);          // chooser of filesystem options.         intent chooserintent = intent.createchooser(galleryintent, "scegli dove prelevare l'immagine");          // add camera options.         chooserintent.putextra(intent.extra_initial_intents, cameraintents.toarray(new parcelable[]{}));         //log.i("sto lanciando il chooser","vado eh");         startactivityforresult(chooserintent, 4982);     }       private string selectedimagepath;     @override     protected void onactivityresult(int requestcode, int resultcode, intent data){         super.onactivityresult(requestcode, resultcode, data);            if (resultcode == result_ok) {             if (requestcode == 4982) {                   uri selectedimageuri = data.getdata();                 selectedimagepath = getpath(selectedimageuri);                 //log.i("immagine",selectedimagepath);                  myimageview.setimagebitmap(decodesampledbitmapfromfile(new file(selectedimagepath)));              }         }      }      public string getpath(uri uri) {         string[] projection = { mediastore.images.media.data };         cursor cursor = managedquery(uri, projection, null, null, null);         int column_index = cursor                 .getcolumnindexorthrow(mediastore.images.media.data);         cursor.movetofirst();         return cursor.getstring(column_index);     }       public static bitmap decodesampledbitmapfromfile(file file) {          // first decode injustdecodebounds=true check dimensions          bitmapfactory.options o = new bitmapfactory.options();             o.injustdecodebounds = true;         bitmapfactory.decodefile(file.getabsolutepath(), o);          //the new size want scale         final int required_size=430;          //find correct scale value. should power of 2.         int scale=1;         while(o.outwidth/scale/2>=required_size && o.outheight/scale/2>=required_size)             scale*=2;          //decode insamplesize         bitmapfactory.options o2 = new bitmapfactory.options();         o2.insamplesize=scale;          return bitmapfactory.decodefile(file.getabsolutepath(), o2);        } 

many android devices, if device held in portrait when picture taken, not rotate image portrait. rather, store image in landscape, , put exif header in image tell image viewer "hey! please rotate 270 degrees!". likely, encountering, know samsung devices have issue.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -