How to find out if the image from the gallery was taken in portrait or landscape from camera
up vote
0
down vote
favorite
- I have a image in gallery which was taken from camera
- I am trying to find out if the image is
portrait
orlandscape
I have the path obtained from below code as
/storage/emulated/0/DCIM/Camera/IMG_20181110_211757.jpg
Then i am using the ExifInterface to find the orientation:
public static void getCameraPhotoOrientation(Activity activity, String imagePath)
String path =getPath(activity,imagePath);
try
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation)
case ExifInterface.ORIENTATION_ROTATE_270:
Timber.d("Type-1");
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Timber.d("Type-2");
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Timber.d("Type-3");
break;
case ExifInterface.ORIENTATION_UNDEFINED:
Timber.d("Type-4");
break;
catch (IOException ex)
ex.printStackTrace();
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
How to resolve this
android exif
add a comment |
up vote
0
down vote
favorite
- I have a image in gallery which was taken from camera
- I am trying to find out if the image is
portrait
orlandscape
I have the path obtained from below code as
/storage/emulated/0/DCIM/Camera/IMG_20181110_211757.jpg
Then i am using the ExifInterface to find the orientation:
public static void getCameraPhotoOrientation(Activity activity, String imagePath)
String path =getPath(activity,imagePath);
try
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation)
case ExifInterface.ORIENTATION_ROTATE_270:
Timber.d("Type-1");
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Timber.d("Type-2");
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Timber.d("Type-3");
break;
case ExifInterface.ORIENTATION_UNDEFINED:
Timber.d("Type-4");
break;
catch (IOException ex)
ex.printStackTrace();
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
How to resolve this
android exif
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
- I have a image in gallery which was taken from camera
- I am trying to find out if the image is
portrait
orlandscape
I have the path obtained from below code as
/storage/emulated/0/DCIM/Camera/IMG_20181110_211757.jpg
Then i am using the ExifInterface to find the orientation:
public static void getCameraPhotoOrientation(Activity activity, String imagePath)
String path =getPath(activity,imagePath);
try
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation)
case ExifInterface.ORIENTATION_ROTATE_270:
Timber.d("Type-1");
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Timber.d("Type-2");
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Timber.d("Type-3");
break;
case ExifInterface.ORIENTATION_UNDEFINED:
Timber.d("Type-4");
break;
catch (IOException ex)
ex.printStackTrace();
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
How to resolve this
android exif
- I have a image in gallery which was taken from camera
- I am trying to find out if the image is
portrait
orlandscape
I have the path obtained from below code as
/storage/emulated/0/DCIM/Camera/IMG_20181110_211757.jpg
Then i am using the ExifInterface to find the orientation:
public static void getCameraPhotoOrientation(Activity activity, String imagePath)
String path =getPath(activity,imagePath);
try
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation)
case ExifInterface.ORIENTATION_ROTATE_270:
Timber.d("Type-1");
break;
case ExifInterface.ORIENTATION_ROTATE_180:
Timber.d("Type-2");
break;
case ExifInterface.ORIENTATION_ROTATE_90:
Timber.d("Type-3");
break;
case ExifInterface.ORIENTATION_UNDEFINED:
Timber.d("Type-4");
break;
catch (IOException ex)
ex.printStackTrace();
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
How to resolve this
android exif
android exif
asked Nov 10 at 16:28
Devrath
22k37132186
22k37132186
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48
add a comment |
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
I have a image in gallery which was taken from camera
There is no way for a developer to guarantee that any particular image came from a camera app, unless the developer is the author of that camera app.
I am trying to find out if the image is portrait or landscape
There is no requirement for an image to be either portrait or landscape. For example, the camera app might crop its photos to be circular or square.
I have the path obtained from below code
That code will fail for lots of Uri
values on lots of devices. If you want to use ExifInterface
for a Uri
, use getContentResolver().openInputStream()
to get an InputStream
on the content identified by the Uri
, then pass that InputStream
to this ExifInterface
constructor.
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
Images do not have to have EXIF headers, let alone ExifInterface.TAG_ORIENTATION
.
If that tag does not exist, you could examine the width and height of the image and make a guess:
- If the width is greater than the height, it might be landscape
- If the height is greater than the width, it might be portrait
This will fail for square images, and this will fail for cropped images (e.g., the photo was taken portrait, but the user cropped it such that the width is now greater than the height).
The best solution is to change your app to not care whether the image is portrait or landscape. The next-best solution is to ask the user how they want to handle the image, where perhaps you use the above algorithm to set the default option.
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
add a comment |
up vote
0
down vote
Try it by changing path accessing process like below
File imFile = new File(imagePath);
ExifInterface ei = new ExifInterface(imFile.getAbsolutePath());
this will explain Android getAbsolutePath() not returning full path it
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I have a image in gallery which was taken from camera
There is no way for a developer to guarantee that any particular image came from a camera app, unless the developer is the author of that camera app.
I am trying to find out if the image is portrait or landscape
There is no requirement for an image to be either portrait or landscape. For example, the camera app might crop its photos to be circular or square.
I have the path obtained from below code
That code will fail for lots of Uri
values on lots of devices. If you want to use ExifInterface
for a Uri
, use getContentResolver().openInputStream()
to get an InputStream
on the content identified by the Uri
, then pass that InputStream
to this ExifInterface
constructor.
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
Images do not have to have EXIF headers, let alone ExifInterface.TAG_ORIENTATION
.
If that tag does not exist, you could examine the width and height of the image and make a guess:
- If the width is greater than the height, it might be landscape
- If the height is greater than the width, it might be portrait
This will fail for square images, and this will fail for cropped images (e.g., the photo was taken portrait, but the user cropped it such that the width is now greater than the height).
The best solution is to change your app to not care whether the image is portrait or landscape. The next-best solution is to ask the user how they want to handle the image, where perhaps you use the above algorithm to set the default option.
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
add a comment |
up vote
2
down vote
accepted
I have a image in gallery which was taken from camera
There is no way for a developer to guarantee that any particular image came from a camera app, unless the developer is the author of that camera app.
I am trying to find out if the image is portrait or landscape
There is no requirement for an image to be either portrait or landscape. For example, the camera app might crop its photos to be circular or square.
I have the path obtained from below code
That code will fail for lots of Uri
values on lots of devices. If you want to use ExifInterface
for a Uri
, use getContentResolver().openInputStream()
to get an InputStream
on the content identified by the Uri
, then pass that InputStream
to this ExifInterface
constructor.
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
Images do not have to have EXIF headers, let alone ExifInterface.TAG_ORIENTATION
.
If that tag does not exist, you could examine the width and height of the image and make a guess:
- If the width is greater than the height, it might be landscape
- If the height is greater than the width, it might be portrait
This will fail for square images, and this will fail for cropped images (e.g., the photo was taken portrait, but the user cropped it such that the width is now greater than the height).
The best solution is to change your app to not care whether the image is portrait or landscape. The next-best solution is to ask the user how they want to handle the image, where perhaps you use the above algorithm to set the default option.
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I have a image in gallery which was taken from camera
There is no way for a developer to guarantee that any particular image came from a camera app, unless the developer is the author of that camera app.
I am trying to find out if the image is portrait or landscape
There is no requirement for an image to be either portrait or landscape. For example, the camera app might crop its photos to be circular or square.
I have the path obtained from below code
That code will fail for lots of Uri
values on lots of devices. If you want to use ExifInterface
for a Uri
, use getContentResolver().openInputStream()
to get an InputStream
on the content identified by the Uri
, then pass that InputStream
to this ExifInterface
constructor.
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
Images do not have to have EXIF headers, let alone ExifInterface.TAG_ORIENTATION
.
If that tag does not exist, you could examine the width and height of the image and make a guess:
- If the width is greater than the height, it might be landscape
- If the height is greater than the width, it might be portrait
This will fail for square images, and this will fail for cropped images (e.g., the photo was taken portrait, but the user cropped it such that the width is now greater than the height).
The best solution is to change your app to not care whether the image is portrait or landscape. The next-best solution is to ask the user how they want to handle the image, where perhaps you use the above algorithm to set the default option.
I have a image in gallery which was taken from camera
There is no way for a developer to guarantee that any particular image came from a camera app, unless the developer is the author of that camera app.
I am trying to find out if the image is portrait or landscape
There is no requirement for an image to be either portrait or landscape. For example, the camera app might crop its photos to be circular or square.
I have the path obtained from below code
That code will fail for lots of Uri
values on lots of devices. If you want to use ExifInterface
for a Uri
, use getContentResolver().openInputStream()
to get an InputStream
on the content identified by the Uri
, then pass that InputStream
to this ExifInterface
constructor.
I always get orientation as ExifInterface.ORIENTATION_UNDEFINED
Images do not have to have EXIF headers, let alone ExifInterface.TAG_ORIENTATION
.
If that tag does not exist, you could examine the width and height of the image and make a guess:
- If the width is greater than the height, it might be landscape
- If the height is greater than the width, it might be portrait
This will fail for square images, and this will fail for cropped images (e.g., the photo was taken portrait, but the user cropped it such that the width is now greater than the height).
The best solution is to change your app to not care whether the image is portrait or landscape. The next-best solution is to ask the user how they want to handle the image, where perhaps you use the above algorithm to set the default option.
answered Nov 10 at 16:45
CommonsWare
760k13718511904
760k13718511904
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
add a comment |
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
I have been reading your answers from a very long time now and wanted to really thank you , you write very detailed and brilliant answers . Could you please help me with my question here
– shashank chandak
Nov 10 at 17:15
add a comment |
up vote
0
down vote
Try it by changing path accessing process like below
File imFile = new File(imagePath);
ExifInterface ei = new ExifInterface(imFile.getAbsolutePath());
this will explain Android getAbsolutePath() not returning full path it
add a comment |
up vote
0
down vote
Try it by changing path accessing process like below
File imFile = new File(imagePath);
ExifInterface ei = new ExifInterface(imFile.getAbsolutePath());
this will explain Android getAbsolutePath() not returning full path it
add a comment |
up vote
0
down vote
up vote
0
down vote
Try it by changing path accessing process like below
File imFile = new File(imagePath);
ExifInterface ei = new ExifInterface(imFile.getAbsolutePath());
this will explain Android getAbsolutePath() not returning full path it
Try it by changing path accessing process like below
File imFile = new File(imagePath);
ExifInterface ei = new ExifInterface(imFile.getAbsolutePath());
this will explain Android getAbsolutePath() not returning full path it
answered Nov 10 at 16:41
Lucefer
1,0481511
1,0481511
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240985%2fhow-to-find-out-if-the-image-from-the-gallery-was-taken-in-portrait-or-landscape%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Get image width and height, if height > width then it is portrait, if width > height then it is landscape, and height = width, square.
– D. B.
Nov 10 at 16:48