Orientation detection for camera capture
I've been searching for a solution to this for some time and believe that it, at it's core, isn't possible.
I'm wondering if anybody has found a decent hack or bypass.
My issue is this:
I have an app that captures a photo, then that photo is used as a canvas that the user can tap on to place tags.
After the tags are placed the user uploads th开发者_如何学JAVAe photos and the tags get submitted to a client service for parsing.
If the photo is taken in landscape I need to detect if it's landscape left or landscape right so that I can display it at the proper orientation when it gets to the canvas, and flip it the proper direction if the user changes to the opposite landscape mode.
How could I capture the orientation that the photo was taken in?
Simply look at the height and width of event.media
to at least determine portrait vs. landscape. This will not help you with which direction to flip, though I'm not sure why you need to figure that out from the capture. The image is saved as a landscape photo in the correct natural orientation, such that you would simply rotate it to the current orientation of the phone
Titanium.Media.showCamera({
success: function(event) {
var isLandscape = event.media.width > event.media.height;
}
}
function getOrientation(o) {
switch (o){
case Titanium.UI.PORTRAIT:
return 'portrait';
case Titanium.UI.UPSIDE_PORTRAIT:
return 'upside portrait';
case Titanium.UI.LANDSCAPE_LEFT:
return 'landscape left';
case Titanium.UI.LANDSCAPE_RIGHT:
return 'landscape right';
case Titanium.UI.FACE_UP:
return 'face up';
case Titanium.UI.FACE_DOWN:
return 'face down';
case Titanium.UI.UNKNOWN:
return 'unknown';
}
}
}
Ti.Gesture.addEventListener('orientationchange',function(e){
Ti.API.info('Current Orientation: ' + getOrientation(Titanium.Gesture.orientation));
var orientation = getOrientation(e.orientation);
Titanium.API.info(
"orientation changed = "+orientation+", is portrait?"+e.source.isPortrait()+", orientation = "+Ti.Gesture.orientation + "is landscape?"+e.source.isLandscape()
);
});
modified a bit from the KS but should do the trick.
this should do what the above doesn't
Titanium.Media.showCamera({
success:function(event) {
var orientationWhilePictureTaken = Ti.Gesture.orientation;
// all other camera code...
}
});
精彩评论