1

I am getting pictures from the sdcard in my app. I am using imageview to display image. However since I dont know if the image will be horizontal or vertical, how can I show horizontal or vertical image in imageview appropriately.Thanks

 File img_file = new File(picture_path);
        bm = BitmapFactory.decodeFile(img_file.getAbsolutePath());
        iv2.setImageBitmap(bm);

imageview xml

 <ImageView
    android:id="@+id/iv_image2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    />
artist
  • 6,271
  • 8
  • 25
  • 35

1 Answers1

1

This is unfortunately kind of a complicated thing to do. You can read the Xif data and determine its orientation, see How to determine orientation of picture without ExifInterface? and Android get Orientation of a camera Bitmap? And rotate back -90 degrees for ideas. Then you can rotate it manually.

Community
  • 1
  • 1
JasonOfEarth
  • 739
  • 7
  • 10
  • I am trying to understand here, the images are being displayed horizontal or vertical. They don't need to be rotated. My problem is if I hard code the width and height in imageview, the portrait images looked weird in height?kind of look shrunk in. Any ideas? – artist Feb 26 '15 at 19:27
  • Ah... Don't hardcode the width and height. use wrap_content for both. That will get the scale correct. If you want to make a hardcoded image size then you have to tell it how to scale or crop, here's a list of your options: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – JasonOfEarth Feb 26 '15 at 19:41