Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26631] Android: image from camera gets rotated to 90 degree

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2019-01-02T20:11:55.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterAminul Islam
AssigneeJoshua Quick
Created2018-12-05T17:02:10.000+0000
Updated2019-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

FileDateSize
Screen Shot 2018-12-05 at 10.21.46 AM.png2018-12-05T17:02:00.000+0000342279
Screen Shot 2018-12-05 at 10.22.11 AM.png2018-12-05T17:01:56.000+0000306377

Comments

  1. Joshua Quick 2018-12-05

    You need to set ImageView property "autorotate" to true. 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" to true, the ImageView will read the JPEG EXIF and rotate the image if needed.
  2. Joshua Quick 2018-12-05

    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.

JSON Source