HTML5 getUserMedia相机焦点

Nie*_*els 10 javascript video mobile html5 camera

我创建了一个简单的移动应用程序,它显示相机并使用https://github.com/LazarSoft/jsqrcode解码QRCodes

因为我的相机模糊,这适用于大QR码.有没有办法用Javascript聚焦相机?所以这也适用于较小的图像或是否有另一种解决方案?

编辑 我注意到如果我使用Android应用程序(而不是HTML5版本),它可以处理更多的色差,并可以扫描我的代码,而jsqrcode不能.我使用错误的库吗?

使用ZXING

我的工作代码:

public void scan() {
    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.initiateScan();
}

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
     // On Scan result we get get to this part
     try {
          IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
          if (scanResult != null) {
            // CODE

          }
     } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

还需要将导入com.google.zxing.integration.android包添加到我的项目中.

Rya*_*ale 1

HTML5 版本是否可以在您的手机上运行? CanIUse建议它不能在除黑莓之外的任何移动设备上运行...但它们有时不是最新的。

不管怎样,是否存在具有这样一个新 API 的万能解决方案值得怀疑。您能了解一下在手机上使用应用程序(本机代码)版本和在桌面上使用支持闪存的版本吗?您必须执行自己的设备嗅探:

if( user_has_flash ) {
    // Load an HTML5/Flash solution
} else if( is_mobile_device) {
    // defer to the native code
    // zxing has a phonegap plugin - https://github.com/wildabeast/BarcodeScanner
} else {
    alert("Your device does not have scanning capabilities");
}
Run Code Online (Sandbox Code Playgroud)