How to check whether the image is Portrait or Landscape in Android?

check if image is rotated android
check orientation of image
android get gallery image orientation
android rotate image based on orientation

Currently, I am working on app which is related to handle pictures. I am modifying the imageview depending on the whether the image is portrait or landscape.

I know I can figure out image is portrait or landscape by comparing the height and width of images.

But the problem I am facing is some images are portrait but the width of image is more than height. Here are those images:



Above images are portrait but if you calculate height and width you will find that width is more than height.

Is there any method in Android which returns whether the image is portrait or landscape?

This method will return the Orientation & rotation required for your image, which you should be able to use to determine whether the image is portrait or landscape.

public int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath){
    int rotate = 0;
    try {
        context.getContentResolver().notifyChange(imageUri, null);
        File imageFile = new File(imagePath);

        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;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;

        Log.i("RotateImage", "Exif orientation: " + orientation);
        Log.i("RotateImage", "Rotate value: " + rotate);
    } catch (Exception e) {
    return rotate;

Landscape vs. Portrait: Which Way is Up?, How do you tell if an image is landscape or portrait? In my appl I check the height and width of the images from gallery. So I know if image is portrait or landscape. However, this does not always work. Some devices take pictures in "portrait" and the width values in the details appears bigger than height.

If I'm understanding question correctly, one approach is to do something like following using Picasso

            Picasso.with(this).load(url).into(new Target() {
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    <compare width/height of bitmap to check aspect ratio of image>

What is a Portrait image and what is landscape?, that is shot so it is taller than it is wide. If the screen width is grater then its height then its Landscape Mode or if the device width is less then it height then it is Portrait Mode. Contents in this project Detect Device Screen Orientation is Portrait or Landscape Android iOS Tutorial : 1. Import  StyleSheet, View and Text component in your project.

I had the same problem. I load a bitmap into the image view, I read the bitmap from the file, and then see if the width is bigger than the height.

if(bitmap.getWidth() > bitmap.getHeight()){
                //meaning the image is landscape view
                view.setLayoutParams(new FrameLayout.LayoutParams(400, ViewPager.LayoutParams.WRAP_CONTENT));
                view.setLayoutParams(new FrameLayout.LayoutParams(250, ViewPager.LayoutParams.WRAP_CONTENT));

Android Question, wider than it is tall - this doesn't work for us so please use a Portrait photo. Android Portrait and Landscape Screen Layout Example. When developing an Android app the Activity screens that form the user interface can be viewed in both portrait and landscape modes. Since Android devices (phones and tablets) can be used in either orientation screen support for both is helpful to the user.

Android Notes 65: How to detect orientation change and get the , In my appl I check the height and width of the images from gallery. So I know if image is portrait or landscape. However, this does not always  This will fail if the screen orientation is fixed. If the activity locks the display (android:screenOrientation="portrait"), this method will return the same value irrespective of how the user rotates the device. In that case you'd use the accelerometer or the gravity sensor to figure out orientation properly.

image-orientation, Your magic here for landscape mode } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Log.d("OrientationMyApp"  You can simply compare width and height of the image. var someImg = $("#someId"); if (someImg.width() > someImg.height()){ //it's a landscape } else if (someImg.width() < someImg.height()){ //it's a portrait } else { //image width and height are equal, therefore it is square.

Managing screen orientation, The image-orientation CSS property specifies a layout-independent the image, or changes required for printing in portrait versus landscape  Most of the Titanium devs are well aware of an issue which turns portrait pictures taken by camera into landscape mode automatically on some Android devices. It really makes devs crazy when they see this issue first time and it can waste their valuable time then.