[AC-5873] Android: Camera and PhotoGallery rotate the selected media Image
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Not Our Bug |
Resolution Date | 2018-10-24T20:16:58.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Ahmed Mohamed |
Assignee | Shak Hossain |
Created | 2018-09-03T11:01:54.000+0000 |
Updated | 2019-03-11T17:14:16.000+0000 |
Description
If take a photo from camera or select one from photoGallery the selected image will be rotated
const window = Ti.UI.createWindow();
const imageView = Ti.UI.createImageView({
top : 0
});
const cameraButton = Ti.UI.createButton({
title : "Camera",
backgroundColor : "teal",
color : "white",
width : "49%",
left : 0,
bottom : 0
});
cameraButton.addEventListener('click', function(e) {
Ti.Media.showCamera({
mediaTypes : [Titanium.Media.MEDIA_TYPE_PHOTO],
success : function(event) {
imageView.image = event.media;
}
});
});
const galleryButton = Ti.UI.createButton({
title : "Gallery",
backgroundColor : "cyan",
color : "white",
width : "49%",
right : 0,
bottom : 0
});
galleryButton.addEventListener('click', function(e) {
if (!Ti.Android.hasPermission("android.permission.READ_EXTERNAL_STORAGE")) {
Ti.Android.requestPermissions("android.permission.READ_EXTERNAL_STORAGE", function(p) {
if (p.success) {
Titanium.Media.openPhotoGallery({
success : function(event) {
imageView.image = event.media;
}
});
}
});
} else {
Titanium.Media.openPhotoGallery({
success : function(event) {
imageView.image = event.media;
}
});
}
});
window.add(imageView);
window.add(cameraButton);
window.add(galleryButton);
window.open();
Hello , Thanks for sharing with us. In which device you are experiencing this? Please share your environment details and a screenshot which displays the issue.
You need to set the
ImageView.autorotate
property totrue
. The will allow theImageView
to read the JPEG's EXIF info to see if it needs to be rotated. https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-property-autorotate For example...Hey Joshua, I want to upload the selected photo to server. So I want to fix the rotation before uploading. Or just know the rotation degree to rotate it with ti.imagefactory module.
Also your solution doesn't work if I take the photo from camera. it worked if I select the photo from Gallery.
Let me help explain what's going on. When you take a photo with a camera, it'll take a picture relative to the camera's physical mounted orientation. The camera app, using sensors, will then detect what upright orientation you are holding the device at and will then either do one of the following:
Save the photo at the camera's mounted orientation and set the JPEG's EXIF orientation to what upright orientation you were holding the camera at.
Save to JPEG already rotated to the orientation you held the camera at, in which case, the JPEG's EXIF orientation will always set to a zero rotation setting.
I find that this is device dependent. Some cameras will pre-rotate the photo before saving it to JPEG, some will not and set the EXIF orientation instead and expect the app to rotate it. You cannot control this. In fact, this is normal for actual cameras (not smart phones). I've testedImageView.autorotate
with a device that does not pre-rotate the JPEG. It definitely rotates the image onscreen. But note that we're not changing the JPEG. We're rotating the image onscreen, which is exactly how it works in iOS and Windows apps. We don't have an API that'll create a new JPEG with upright orientation. I suppose what you can do instead is display the photo in anImageView
and then take a screenshot of it viewImageView.toImage()
, but the major downside to this is that you cannot retain the original resolution of the photo. In order to take a screenshot reliably, you have to shrink the image to fit within the bounds of the screen before saving a new JPEG and odds are it's going to be much smaller than the original.Hey @Joshua today i submit PR to ti.imagefactory for fixing this issue PR https://github.com/appcelerator-modules/ti.imagefactory/pull/32