Camera Intent Image Preview Orientation
up vote
0
down vote
favorite
I take an image in Android using the following Code:
File image = new File(this.images_object_dir, loadedObjekt.getFilename());
Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_ACTIVITY_CODE);
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.
Is there a solution for this?
java android android-intent camera
add a comment |
up vote
0
down vote
favorite
I take an image in Android using the following Code:
File image = new File(this.images_object_dir, loadedObjekt.getFilename());
Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_ACTIVITY_CODE);
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.
Is there a solution for this?
java android android-intent camera
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I take an image in Android using the following Code:
File image = new File(this.images_object_dir, loadedObjekt.getFilename());
Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_ACTIVITY_CODE);
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.
Is there a solution for this?
java android android-intent camera
I take an image in Android using the following Code:
File image = new File(this.images_object_dir, loadedObjekt.getFilename());
Uri uri = FileProvider.getUriForFile(this, FILE_PROVIDER, image);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_ACTIVITY_CODE);
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro. On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly. For instance, if you want to take an image in landscape mode, the preview gets flipped to portrait mode.
Is there a solution for this?
java android android-intent camera
java android android-intent camera
edited Nov 10 at 18:28
Kling Klang
32k156286
32k156286
asked Nov 10 at 15:46
Herry
11
11
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.
Your code might start any of them.
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro
That is the behavior of that one camera app out of hundreds.
On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.
That is the behavior of that one camera app out of hundreds.
There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.
Is there a solution for this?
If you wish to use ACTION_IMAGE_CAPTURE
, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.
There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
add a comment |
up vote
0
down vote
Use ExifInterface
to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
If you want to use support library in order to support devices with lower API levels, use the following dependency:
implementation 'com.android.support:exifinterface:27.1.1'
and import android.support.media.ExifInterface
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
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
There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.
Your code might start any of them.
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro
That is the behavior of that one camera app out of hundreds.
On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.
That is the behavior of that one camera app out of hundreds.
There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.
Is there a solution for this?
If you wish to use ACTION_IMAGE_CAPTURE
, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.
There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
add a comment |
up vote
2
down vote
There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.
Your code might start any of them.
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro
That is the behavior of that one camera app out of hundreds.
On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.
That is the behavior of that one camera app out of hundreds.
There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.
Is there a solution for this?
If you wish to use ACTION_IMAGE_CAPTURE
, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.
There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
add a comment |
up vote
2
down vote
up vote
2
down vote
There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.
Your code might start any of them.
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro
That is the behavior of that one camera app out of hundreds.
On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.
That is the behavior of that one camera app out of hundreds.
There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.
Is there a solution for this?
If you wish to use ACTION_IMAGE_CAPTURE
, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.
There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.
There are ~2 billion Android devices, spread across ~20,000 device models. There are dozens, if not hundreds, of pre-installed camera apps across those device models. There are plenty of other camera apps that the user can download and install.
Your code might start any of them.
In the camera intent, the image preview is always in portrait mode on my Huawei P20 Pro
That is the behavior of that one camera app out of hundreds.
On another test-device the preview image (the one where you can decide if you wanna retake the image) is stuck in the "inital" rotation as well which looks ugly.
That is the behavior of that one camera app out of hundreds.
There is no requirement for a camera app to behave that way. Of course, there is no requirement for a camera app to have preview images at all.
Is there a solution for this?
If you wish to use ACTION_IMAGE_CAPTURE
, no. The behavior of those hundreds of camera apps is up to the developers of those camera apps, not you.
There are other options for taking pictures, such as using the camera APIs directly or using third-party libraries like Fotoapparat or CameraKit-Android.
answered Nov 10 at 15:52
CommonsWare
756k13618441897
756k13618441897
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
add a comment |
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
Still, there may be good reasons to use the intent. The end user does not care about inconsistent behaviour between different devices and different camera apps. After all, we expect that the user chooses the camera app that delivers the best results, and already saw the same ugly preview screen with other apps that use camera intent, including Google Keep and other quite respectable publishers.
– Alex Cohn
Nov 12 at 14:15
add a comment |
up vote
0
down vote
Use ExifInterface
to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
If you want to use support library in order to support devices with lower API levels, use the following dependency:
implementation 'com.android.support:exifinterface:27.1.1'
and import android.support.media.ExifInterface
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
add a comment |
up vote
0
down vote
Use ExifInterface
to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
If you want to use support library in order to support devices with lower API levels, use the following dependency:
implementation 'com.android.support:exifinterface:27.1.1'
and import android.support.media.ExifInterface
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
add a comment |
up vote
0
down vote
up vote
0
down vote
Use ExifInterface
to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
If you want to use support library in order to support devices with lower API levels, use the following dependency:
implementation 'com.android.support:exifinterface:27.1.1'
and import android.support.media.ExifInterface
Use ExifInterface
to check the orientation of the image while decoding it. Then you rotate the image to get required image in proper orientation.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable = true;
Bitmap decoded = BitmapFactory.decodeFile(filePath, options);
if (decoded == null) return null;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotation = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
rotation = 90;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
rotation = 270;
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
rotation = 180;
}
if (rotation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
Bitmap newBitmap = Bitmap.createBitmap(decoded, 0, 0, decoded.getWidth(),
decoded.getHeight(), matrix, true);
decoded.recycle();
Runtime.getRuntime().gc();
decoded = newBitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
If you want to use support library in order to support devices with lower API levels, use the following dependency:
implementation 'com.android.support:exifinterface:27.1.1'
and import android.support.media.ExifInterface
answered Nov 10 at 15:53
Nabin Bhandari
8,76521534
8,76521534
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
add a comment |
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
The image itself is correctly rotated after the camera intent ends - in the Android camera intent itself the picture is rotated in a weird way.
– Herry
Nov 10 at 16:30
add a comment |
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%2f53240588%2fcamera-intent-image-preview-orientation%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