-1

I have this code to preview an image loaded from the phone, the problem is when I use camera to take image and load it to my app it gets rotated 90 degrees. What could be causing this behavior? This is my code:

 private void addImageToGrid(String selectedImageUri) {
    Bitmap bitmap = getBitmapFromPath(selectedImageUri);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 8;
    int bitmapWidth = 90;//bitmap.getScaledWidth(density);
    int bitmapHeight = 80;// bitmap.getScaledWidth(density);
    ImageItem imageItem = new ImageItem();
    imageItem.setImage(Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));
    imageItem.setUri(selectedImageUri);
    gridViewAdapter.add(imageItem);

}

Fuluza
  • 109
  • 2
  • 13
  • have you tried reading this : http://stackoverflow.com/questions/14066038/why-image-captured-using-camera-intent-gets-rotated-on-some-devices-in-android – zerocool Nov 16 '16 at 08:28

2 Answers2

0

While some android devices (or camera apps) really produce a bitmap corresponding to the device orientation (i.e. landscape vs portrait) others always use a landscape bitmap and only put the orientation information into the EXIF data packed into the JPEG file. It depends then on the viewer if the image is displayed correctly or not.

Henry
  • 42,982
  • 7
  • 68
  • 84
0

Because some devices will auto rotate the camera, some devices will use only portrait other only landscape you have to check the image what you select is it portrait or it is landscape by verify width and height.

So first check the Bitmap bitmap orientation and apply a rotation like this:

enter link description here

Community
  • 1
  • 1
matheszabi
  • 594
  • 5
  • 16