最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML5 getUserMedia camera focus - Stack Overflow

programmeradmin0浏览0评论

I've created a simple mobile application which shows the camera and decodes QRCodes with

Because my camera is blurry, this works for big QRCodes. Is there a way to focus the camera with Javascript? So this also works for smaller images or is there another solution?

EDIT I've noticed that if I use the Android App (instead of the HTML5 version), it can handle way more color difference and can scan my codes, while jsqrcode cannot. Am I using the wrong library?

Using ZXING

My working code:

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();
    }
}

Also needed to add the import .google.zxing.integration.android package to my project.

I've created a simple mobile application which shows the camera and decodes QRCodes with https://github./LazarSoft/jsqrcode

Because my camera is blurry, this works for big QRCodes. Is there a way to focus the camera with Javascript? So this also works for smaller images or is there another solution?

EDIT I've noticed that if I use the Android App (instead of the HTML5 version), it can handle way more color difference and can scan my codes, while jsqrcode cannot. Am I using the wrong library?

Using ZXING

My working code:

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();
    }
}

Also needed to add the import .google.zxing.integration.android package to my project.

Share Improve this question edited Feb 28, 2014 at 15:32 Niels asked Nov 26, 2013 at 14:24 NielsNiels 50k4 gold badges66 silver badges84 bronze badges 4
  • Did you get anywhere with this? I'm trying to access the rear camera with the 'environment' mand, however as you suggest, it won't focus and is no good for scanning? – andybarnes Commented Feb 28, 2014 at 8:30
  • As far is I discovered it is not possible. Currently I am using the XZing scan app (there are multiple demos on the internet) and open that APP from my app and let it scan. That app has full scan positiblities. – Niels Commented Feb 28, 2014 at 10:04
  • Thanks for that, I'll investigate! – andybarnes Commented Feb 28, 2014 at 11:12
  • Added some of my code. GL – Niels Commented Feb 28, 2014 at 15:33
Add a ment  | 

1 Answer 1

Reset to default 1

Is the HTML5 version even working on your phone at all? CanIUse suggests that it shouldn't work on any mobile device except blackberry... but they are sometimes not up-to-date.

Either way - doubtful there's a one-size-fits-all solution with such a new API. Can you see about using the app (native code) version on phones and the flash-enabled version for desktops. You will have to perform your own device sniffing:

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./wildabeast/BarcodeScanner
} else {
    alert("Your device does not have scanning capabilities");
}
发布评论

评论列表(0)

  1. 暂无评论