[TIMOB-26631] Android: image from camera gets rotated to 90 degree
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2019-01-02T20:11:55.000+0000 |
Affected Version/s | Release 7.5.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Aminul Islam |
Assignee | Joshua Quick |
Created | 2018-12-05T17:02:10.000+0000 |
Updated | 2019-01-02T20:11:59.000+0000 |
Description
Hello!
I'm trying to take an image from the camera and then save it to the image view or post it to my server for Android. The problem is when I take the image it gets rotated to 90 degrees.
Test Code:
var win = Ti.UI.createWindow({
backgroundColor: '#fff',
title: 'Test',
layout:"vertical"
});
var button = Ti.UI.createButton({
title: 'Post Item'
});
button.addEventListener('click', function(e) {
var dialog = Ti.UI.createOptionDialog({
options: ['Take a Picture', 'Choose a Picture'],
cancel: 2
});
dialog.addEventListener('click', function(e) {
if(e.index == 0) {
Ti.Media.showCamera({
success: function(e) {
alert('media.nativePath: ' + e.media.nativePath);
// create an imageView to display our photo
var imageView = Ti.UI.createImageView({
image: e.media
});
// add the imageView to the window
win.add(imageView);
},
cancel: function(e) {
Ti.API.info(JSON.stringify(e));
},
error: function(e) {
Ti.API.info(JSON.stringify(e));
},
animated: false,
autohide: true,
saveToPhotoGallery: false,
showControls: true
});
}
else if(e.index == 1) {
Ti.Media.openPhotoGallery({
success: function(e) {
alert('media.nativePath: ' + e.media.nativePath);
},
cancel: function(e) {
Ti.API.info(JSON.stringify(e));
},
error: function(e) {
Ti.API.info(JSON.stringify(e));
},
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
});
}
});
dialog.show();
});
win.add(button);
//check if we already have permissions to capture media
if (!Ti.Media.hasCameraPermissions()) {
// request permissions to capture media
Ti.Media.requestCameraPermissions(function (e) {
// success! display the camera
if (e.success) {
win.open();
// oops! could not obtain required permissions
} else {
callback(new Error('could not obtain camera permissions!'), null);
}
});
} else {
win.open();
}
Tets Environment:
Operating System
Name = Microsoft Windows 10 Pro
Version = 10.0.17134
Architecture = 32bit
# CPUs = 4
Memory = 17091956736
Node.js
Node.js Version = 8.9.1
npm Version = 5.5.1
Titanium CLI
CLI Version = 5.1.1
Titanium SDK
SDK Version = 7.5.0.GA
SDK Path = C:\ProgramData\Titanium\mobilesdk\win32\7.5.0.GA
Target Platform = android
Please take a look on attached screenshot. Also note, that front and back facing cameras rotate the image different ways
Thanks
Attachments
File | Date | Size |
---|---|---|
Screen Shot 2018-12-05 at 10.21.46 AM.png | 2018-12-05T17:02:00.000+0000 | 342279 |
Screen Shot 2018-12-05 at 10.22.11 AM.png | 2018-12-05T17:01:56.000+0000 | 306377 |
You need to set
ImageView
property "autorotate" totrue
. Please see... https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ImageView-property-autorotate The reason this is happening is because some cameras will save the JPEG based on the camera's mounted orientation. In this case, the camera will store the orientation the device was held to the JPEG file's EXIF information. When setting "autorotate" totrue
, theImageView
will read the JPEG EXIF and rotate the image if needed.This solution works on all phones and Android OS versions I've tested it on. If it's not working for a particular JPEG, then that may suggest that the JPEG does not have the orientation stored to its EXIF.