简体   繁体   English

移动设备上的HTML5 / javascript条形码阅读器,无需手动切换分辨率

[英]HTML5/ javascript barcode reader on mobile without manually switching resolution

I am trying to do barcode reading in HTML5/ Javascript on mobile so I can extract the barcode and post to a Ruby on Rails web service. 我正在尝试在移动设备上使用HTML5 / Javascript读取条形码,以便提取条形码并将其发布到Ruby on Rails Web服务。

I am using this code for barcode reading: code by manuels which works fine ( You can try out the barcode reader code here ) if camera on mobile is set to a very low resolution, not at high resolution though. 我正在使用此代码进行条形码读取:如果移动电话上的摄像头设置为非常低的分辨率,而不是高分辨率,则可以很好地使用manuels的代码您可以在此处尝试使用条形码阅读器的代码 )。 This method using HTML Media Capture is not ideal as user would have to switch to low resolution manually. 这种使用HTML Media Capture的方法并不理想,因为用户必须手动切换到低分辨率。 I know one can set resolution using GetUserMedia but it's not compatible with many browser/ versions. 我知道可以使用GetUserMedia设置分辨率,但是它与许多浏览器/版本都不兼容。

I am trying to resize the captured photo using a canvas, based on the canvas code here (not written by myself) . 我正在尝试根据此处的画布代码(不是由我自己编写)使用画布来调整捕获的照片的大小。 The resize works as expect. 调整大小按预期工作。 I then combine the barcode reading code mentioned above in the resize function as below but the barcode reading part doesn't work. 然后,我将上述条形码读取代码与以下调整大小功能结合在一起,但是条形码读取部分不起作用。

... var interface = new Interface('./bardecode-worker.js'); ... var interface = new Interface('./ bardecode-worker.js'); interface.on_stdout = function(x) { document.getElementById('barcode').appendChild(document.createTextNode('result: '+x)); interface.on_stdout = function(x){document.getElementById('barcode')。appendChild(document.createTextNode('result:'+ x)); }; }; ... ...

interface.addData(tempCanvas.toDataURL('image/jpeg'), '/barcode.jpg').then
(
    function()
    {
        interface.run('/barcode.jpg').then
        (
            function() { console.log(arguments); }
        );
    }
)

This is manuels' original code below, and in the above code, I am trying to feed the resized image from the canvas into the interface.js instead of a FileReader: 这是下面manuels的原始代码,在上面的代码中,我试图将调整大小后的图像从画布输入到interface.js中,而不是FileReader中:

document.getElementById('barcode_file').onchange = function(e) {
    var file = e.target.files[0];
    var reader = new FileReader();

    document.getElementById('barcode').appendChild(document.createTextNode('running...'));

    reader.onload = function(ev) {
        interface.addData(ev.target.result, '/barcode.jpg').then(function() {
             interface.run('/barcode.jpg').then(function() { console.log(arguments); });
        })
    };
    reader.readAsBinaryString(file);
};

Sorry, I am quite new to javascript. 抱歉,我对javascript很陌生。 Any suggestions? 有什么建议么? Or is there a better solution? 还是有更好的解决方案?

You might be interested in looking at this program which specializes in providing easier access to hardware on mobile phones. 您可能对查看此程序感兴趣,该程序专门提供对移动电话上硬件的轻松访问。

http://bridgeit.mobi/ http://bridgeit.mobi/

It installs a native app on the phone and then lets you open the app from your webpage and then passes back the scan or photo or other item. 它会在手机上安装本机应用程序,然后让您从网页上打开该应用程序,然后将扫描或照片或其他项目传回。

They use a javascript library they wrote to open the app and then pass the information back to your webpage. 他们使用自己编写的JavaScript库打开应用程序,然后将信息传递回您的网页。

The library will also open the store page of the program if it is not installed the first time it a user tries to use it. 如果该库在用户第一次尝试使用该程序时未安装,它还将打开该程序的商店页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM