Camera capture orientation on samsung devices in android -


i creating camera app. image when captured shown in grid view. now, code working fine on devices except samsung devices.

i facing orientation issue. when capture image in portrait mode, image rotates when displayed in gridview. have not kept rotate code. secondly, exif achieved proper image in grid view when device orientation changes, again image rotates in wiered fashion.

attaching images: enter image description here

enter image description here

sorry resolution of image. please lemme know if not visible properly. upload again. know there lot such on so. guess stuck somewhere.

i referring following link:

http://blog.andolasoft.com/2013/06/how-to-show-captured-images-dynamically-in-gridview-layout.html

this code i've done (it working every device):

this part set taken photo imageview in main activity:

            try {                 file imagefile = new file(cursor.getstring(0));                 exifinterface exif = new exifinterface(                         imagefile.getabsolutepath());                 int orientation = exif.getattributeint(                         exifinterface.tag_orientation,                         exifinterface.orientation_normal);                 switch (orientation) {                 case exifinterface.orientation_rotate_270:                     rotate = 270;                     break;                 case exifinterface.orientation_rotate_180:                     rotate = 180;                     break;                 case exifinterface.orientation_rotate_90:                     rotate = 90;                     break;                 }                  log.v("", "exif orientation: " + orientation);             } catch (exception e) {                 e.printstacktrace();             }             matrix matrix = new matrix();             matrix.postrotate(rotate);             bmp = bitmap.createbitmap(bmp, 0, 0, bmp.getwidth(), bmp.getheight(), matrix, true);             testimage.setimagebitmap(null);             testimage.setimagebitmap(bmp); 

constant values in camera activity:

  private static final int orientation_portrait_normal =  1;   private static final int orientation_portrait_inverted =  2;   private static final int orientation_landscape_normal =  3;   private static final int orientation_landscape_inverted =  4;   private orientationeventlistener morientationeventlistener;   private int morientation =  -1; 

callback function in camera activity:

      camera.picturecallback photocallback=new camera.picturecallback(){           public void onpicturetaken(final byte[] data, final camera camera){                dialog=progressdialog.show(cameraactivity.this,"","please wait while photo being saved..");               new thread(){                   public void run(){                       try{                           thread.sleep(1000);                                }                       catch(exception ex){}                       onpicturetake(data,camera);                        }               }.start();                 }       }; 

take photo function in camera activity:

      public void onpicturetake(byte[] data, camera camera){           switch (morientation) {           case orientation_portrait_normal:               rotate = 90;               break;           case orientation_landscape_normal:               rotate = 0;               break;           case orientation_portrait_inverted:               rotate = 270;               break;           case orientation_landscape_inverted:               rotate = 180;               break;           }            matrix matrix = new matrix();           matrix.postrotate(rotate);           bmp = bitmapfactory.decodebytearray(data, 0, data.length);           bmp = bitmap.createbitmap(bmp, 0, 0, bmp.getwidth(), bmp.getheight(), matrix, true);           mutablebitmap = bmp.copy(bitmap.config.argb_8888, true);           savephoto(mutablebitmap);           dialog.dismiss();           flag = 0;           finish();       } 

orientation listenner called in onresume in camera activity:

morientationeventlistener = new orientationeventlistener(this, sensormanager.sensor_delay_normal) {                  @suppresswarnings("deprecation")                 @override                 public void onorientationchanged(int orientation) {                      // determine our orientation based on sensor response                     int lastorientation = morientation;                      display display = ((windowmanager)getsystemservice(window_service)).getdefaultdisplay();                        int rotation = getwindowmanager().getdefaultdisplay().getrotation();                     system.out.println(rotation+"");                  if (display.getorientation() != surface.rotation_0) {   // landscape oriented devices                         system.out.println("landscape");                         if (orientation >= 315 || orientation < 45) {                             if (morientation != orientation_landscape_normal) {                                                          morientation = orientation_landscape_normal;                             }                         } else if (orientation < 315 && orientation >= 225) {                             if (morientation != orientation_portrait_inverted) {                                 morientation = orientation_portrait_inverted;                             }                                                } else if (orientation < 225 && orientation >= 135) {                             if (morientation != orientation_landscape_inverted) {                                 morientation = orientation_landscape_inverted;                             }                                                } else if (orientation <135 && orientation > 45) {                              if (morientation != orientation_portrait_normal) {                                 morientation = orientation_portrait_normal;                             }                                                }                                            } else {  // portrait oriented devices                         system.out.println("portrait");                         if (orientation >= 315 || orientation < 45) {                             if (morientation != orientation_portrait_normal) {                                                           morientation = orientation_portrait_normal;                             }                         } else if (orientation < 315 && orientation >= 225) {                             if (morientation != orientation_landscape_normal) {                                 morientation = orientation_landscape_normal;                             }                                                } else if (orientation < 225 && orientation >= 135) {                             if (morientation != orientation_portrait_inverted) {                                 morientation = orientation_portrait_inverted;                             }                                                } else if (orientation <135 && orientation > 45) {                              if (morientation != orientation_landscape_inverted) {                                 morientation = orientation_landscape_inverted;                             }                                                }                     }                  }             }; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -