我正在尝试在移动设备上使用HTML5 / Javascript进行条形码阅读,这样我就可以提取条形码并发布到Ruby on Rails网络服务。
我正在使用此代码进行条形码阅读:code by manuels如果手机上的相机设置为非常低的分辨率,而不是高分辨率,则可以正常工作(You can try out the barcode reader code here)。使用HTML Media Capture的此方法并不理想,因为用户必须手动切换到低分辨率。我知道可以使用GetUserMedia设置分辨率,但它与许多浏览器/版本不兼容。
我正在尝试使用画布调整捕获的照片大小,基于画布代码here (not written by myself)。调整大小按预期工作。然后我在调整大小函数中将上面提到的条形码读取代码组合如下,但条形码读取部分不起作用。
... var interface = new Interface('./ bardecode-worker.js'); 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); }
);
}
)
这是下面的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);
};
抱歉,我是javascript的新手。有什么建议?或者有更好的解决方案吗?
答案 0 :(得分:0)
您可能有兴趣查看此计划,该计划专门提供更方便的手机硬件访问。
它会在手机上安装原生应用,然后让您从网页打开应用,然后传回扫描或照片或其他项目。
他们使用他们编写的javascript库打开应用程序,然后将信息传回您的网页。
如果用户第一次尝试使用它时,库也会打开程序的商店页面。