相机捕捉的方向检测

发布于 2024-11-02 03:09:04 字数 309 浏览 4 评论 0原文

一段时间以来,我一直在寻找解决方案,并且相信从本质上讲,这是不可能的。

我想知道是否有人找到了合适的黑客或绕过方法。

我的问题是这样的:

我有一个应用程序可以捕获照片,然后将该照片用作画布,用户可以点击该画布来放置标签。

放置标签后,用户上传照片,并将标签提交给客户端服务进行解析。

如果照片是横向拍摄的,我需要检测它是横向左还是横向右,以便当它到达画布时我可以以正确的方向显示它,并在用户更改为正确的方向时将其翻转到正确的方向相反的横向模式。

我如何捕捉照片拍摄的方向?

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 the 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薔薇婲 2024-11-09 03:09:04

只需查看 event.media 的高度和宽度即可至少确定纵向与横向。这不会帮助您确定要翻转的方向,尽管我不确定为什么您需要从捕获中弄清楚这一点。图像以正确的自然方向保存为风景照片,以便您只需将其旋转到手机的当前方向

Titanium.Media.showCamera({
    success: function(event) { 
        var isLandscape = event.media.width > event.media.height;
    }
}

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;
    }
}
此生挚爱伱 2024-11-09 03:09:04
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()
    );
});

KS 进行了一些修改,但应该可以解决问题。

这应该做上面没有做的事情

Titanium.Media.showCamera({
    success:function(event) {
    var orientationWhilePictureTaken = Ti.Gesture.orientation;
        // all other camera code...
    }
});
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...
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文