【问题标题】:Cross device photo capture for upload跨设备拍照上传
【发布时间】:2014-09-15 16:14:55
【问题描述】:

自 iOS6 以来,移动 Safari 浏览器的用户已经能够通过相机或相册从他们的设备上传图像。

Web 开发者只需要编写一个绑定文件输入标签的上传脚本,如下所示:

<input type="file" accept="image/*" capture="camera">

这将提示 iOS 用户选择图像源(图像文件或相机),然后将图像上传到服务器。类似于这张图片。

这适用于带有 Mobile Safari 的 iOS,但是,我希望在 Windows Phone、Android 以及 iOS iPhone 和 iPad 中具有相同的行为。

每种设备是否有类似的 HTML 规范?

您可以在他的回答中使用Chris Droukas 提供的this 链接进行尝试。

谢谢。

编辑:

我有机会在 Android 4.2 和 iOS6 上尝试&lt;input type="file" accept="image/*" capture="camera"&gt;,并且两者都允许用户拍照(或选择一张)并提交。

有更多设备的人可以告诉我这是否适合他们吗?

【问题讨论】:

  • 根据the spec,capture 是一个布尔属性,不应该接受像camera 这样的值。

标签: android ios html mobile windows-phone


【解决方案1】:

根据this chart,HTML Media Capture可用于以下移动平台:

iOS Safari:6.0 及更高版本

Android 浏览器:3.0 及更高版本

谷歌浏览器:4.0 及更高版本

黑莓浏览器:BB10

Opera Mobile(Android 和 Symbian):14.0 及更高版本

Firefox(Android、MeeGo):11.0 及更高版本

Windows Phone 上的 Internet Explorer 似乎不支持它。你可以在不同的设备上测试here。

【讨论】:

    【解决方案2】:

    使用PhoneGap:

    <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
    
    <script>
    function takePicture() {
        navigator.camera.getPicture(
            function (uri) {
                var img = document.getElementById('camera_image');
                img.style.visibility = "visible";
                img.style.display = "block";
                img.src = uri;
                document.getElementById('camera_status').innerHTML = "Success";
            },
            function(e) {
                console.log("Error getting picture: " + e);
                document.getElementById('camera_status').innerHTML = "Error getting picture.";
            },
            { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI});
    };
    </script>
    
    
    <input type="button" onclick="takePicture();" value="Take Picture" /><br/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      • 2010-12-10
      • 2021-10-18
      相关资源
      最近更新 更多