JavaScript QR 码阅读器 - 可以做到吗?或者,远程服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2566972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript QR Code Reader - can it be done? Or, Remote Service?
提问by Myk
I'm doing a bit of preliminary research on an upcoming project and I have a quick question that I figure I'll throw up here while I look elsewhere, in case anyone has any experience with this.
我正在对即将到来的项目进行一些初步研究,我有一个快速的问题,我想我会在寻找其他地方的同时抛出这里,以防万一有人对此有任何经验。
The question is simple: is it possible to read a QR code using JavaScript? Is there a remote service to which I can pass a bitmap object from a camera and do it that way? Are there currently any libraries that allow this?
问题很简单:是否可以使用 JavaScript 读取二维码?是否有远程服务可以将位图对象从相机传递到该服务并以这种方式执行?目前是否有任何图书馆允许这样做?
The project is going to be deployed to various mobile devices and we'd like to try to use Appcelerator to make it work. I know Appcelerator does expose the Camera API on its host devices, but whatever we do with it has to be able to parse QR codes. Is this something that can be done?
该项目将部署到各种移动设备上,我们想尝试使用 Appcelerator 使其工作。我知道 Appcelerator 确实在其主机设备上公开了 Camera API,但无论我们用它做什么,都必须能够解析 QR 码。这是可以做到的吗?
Thanks in advance! myk
提前致谢!米克
回答by dave1010
I bet it's possible, but it would be a challenge. Someone's written an AS3 library for reading QR codes. I'd start by reading up on image manipulation in Canvas.
我打赌这是可能的,但这将是一个挑战。有人编写了一个用于读取 QR 码的AS3 库。我首先阅读Canvas 中的图像处理。
If you go down the remote API route, Kaywahave an API you may be able to use.
如果你走远程 API 路线,Kaywa有一个你可以使用的 API。
回答by Bugster
回答by Jab2870
You can use the getUserMediaAPI to get video from the webcam and you could put it into a canvas element and use the canvas to read the pixels and decode a QR code.
您可以使用getUserMediaAPI 从网络摄像头获取视频,并将其放入画布元素并使用画布读取像素并解码二维码。
I don't know of a library to decode QR codes but here is one librarythat can do bar codes.
回答by alunny
Because of memory limits for JavaScript on mobile devices, it's likely to take too long for practical use, if it is possible with purely JS.
由于移动设备上 JavaScript 的内存限制,如果纯 JS 可能的话,实际使用可能需要很长时间。
I don't know exactly how the Appcelerator API works with external native libraries, but your best bet is to pass the image data to the native code (Objective-C or Java) and then use a lower-level library (like iphone-qrcode) to parse the QR code, then pass the result back to the JS execution context.
我不知道 Appcelerator API 如何与外部本机库一起工作,但最好的办法是将图像数据传递给本机代码(Objective-C 或 Java),然后使用较低级别的库(如iphone-qrcode) 来解析二维码,然后将结果传回 JS 执行上下文。
This has the added advantage of working offline, which a remote service could not do.
这具有离线工作的额外优势,这是远程服务无法做到的。
回答by Anurag
If you want a proof-of-concept, then here it is - a motion trackerwritten in pure Javascript.
如果你想要一个概念验证,那么它就是一个用纯 Javascript 编写的运动跟踪器。
However, support for it is not widespread right now. Only FF and the latest Webkit builds support it afaik.
但是,目前对它的支持并不普遍。只有 FF 和最新的 Webkit 版本才支持它。
Just noticed that you wanted this for a mobile device. Then absolutely go with a remote service. It will be really taxing even on the most high end devices assuming they even support it, which I highly doubt.
刚刚注意到你想要这个用于移动设备。然后绝对使用远程服务。假设他们甚至支持它,即使在最高端的设备上也会非常费力,我非常怀疑。

