2014-02-14 48 views
3

我正在尋找掃描條形碼並根據是否收到條形碼返回響應的方式。我可以找到唯一的結果指向英特爾XDK。我不能在這個特定的項目中使用它,所以沒有它可以做到這一點? 如何使用HTML5/JavaScript掃描條形碼?在HTML5/JavaScript中掃描條形碼

Here is the link I found originally,看起來如果我能夠使用英特爾XDK,它可以完成這項工作。讓我知道我可以在這個問題上增加更多的內容,我只需要指出正確的方向,因爲我不知道從何處開始或者在訪問相機後如何進行實際掃描。下面是我使用的訪問和顯示設備攝像頭的代碼:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta content="stuff, to, help, search, engines, not" name="keywords"> 
<meta content="What this page is about." name="description"> 
<meta content="Display Webcam Stream" name="title"> 
<title>Display Webcam Stream</title> 

<style> 
#container { 
    margin: 0px auto; 
    width: 500px; 
    height: 375px; 
    border: 10px #333 solid; 
} 
#videoElement { 
    width: 500px; 
    height: 375px; 
    background-color: #666; 
} 
</style> 
</head> 

<body> 
<div id="container"> 
    <video autoplay="true" id="videoElement" controls="true"> 

    </video> 
</div> 
<script> 
var video = document.querySelector("#videoElement"); 

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia; 

if (navigator.getUserMedia) 
{  
    navigator.getUserMedia({video: true}, handleVideo, videoError); 
} 

function handleVideo(stream) 
{ 
    video.src = window.URL.createObjectURL(stream); 
} 

function videoError(e) 
{ 
    alert("I don't understand. Why did you not allow it?"); 
} 
</script> 
</body> 
</html> 
+0

我想我半小時前也看到了這個問題,但無法再找到它。你重做了你的問題嗎? –

回答

1

大部分時間條形碼掃描器像鍵盤 - 他們的「類型」的結果。您可以通過監聽按鍵事件或通過監聽輸入字段中的更改來捕獲它。

有關捕獲條形碼的特定技術的更多信息將需要更詳細地回答這個問題。

+0

我們可能會在尋找某種智能手機。現在讓我們說一個iPhone。它只是一個HTML5應用程序(本地應用程序顯然是一種非常不同的情況),所以我正在研究如何完成。 – muttley91

+0

這聽起來像你想從攝像機拍攝的圖像中解碼條形碼。除非你知道如何從圖像中解碼條形碼,否則你運氣不好。圖像處理是它自己的特色,通常不在JavaScript的可用範圍之內。 –

+0

看這裏:http://stackoverflow.com/search?q=decode+barcode+from+image –