[英]How to read a QR code directly from a mobile camera using ZXing [ASP.Net WebForm]
我目前正在開展一個由患者數據庫組成的醫療項目。 每次將患者添加到記錄中時,我使用zxing生成QR碼,QR碼包含患者的ID。
生成代碼如下
//GENERATE QRCODE
private void GenerateCode(string patientIdString)
{
var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
var result = writer.Write(patientIdString);
string path = Server.MapPath("~/images/" + patientIdString + ".jpg");
var barcodeBitmap = new Bitmap(result);
using (MemoryStream memory = new MemoryStream())
{
using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
{
barcodeBitmap.Save(memory, ImageFormat.Jpeg);
byte[] bytes = memory.ToArray();
fs.Write(bytes, 0, bytes.Length);
}
}
patientQRCode.Visible = true;
patientQRCode.ImageUrl = "~/images/"+ patientIdString + ".jpg";
}
然后在AddPatient功能上調用此方法,該功能完全正常。
在我的掃描頁面上,我有兩個功能,用戶點擊在dataTable上查看的患者ID,將其重定向到視圖患者頁面,或者用戶具有使用他們的移動相機的功能。
讀取QR碼並翻譯的代碼如下
//READ CODE FROM QR IMAGE
private void ReadQRCode()
{
var reader = new BarcodeReader();
string filename = Path.Combine(Request.MapPath("~/images/"), "QRImage.jpg");
//Detatch and decode the barcode inside the bitmap
var result = reader.Decode(new Bitmap(filename));
if (result != null)
{
lblQRCode.Text = "QR Code : " + result.Text;
}
}
我用於移動用戶打開相機的方法如下:
<p class="lead" style="text-align: center"><input class="btn btn-success btn-sm" type="file" accept="image/*" runat="server" capture="camera" /></p>
問題是相機實際上並沒有掃描/拍照,它只是作為一個鏡頭。 有沒有辦法讓它讀取並轉換代碼以獲取患者ID,然后自動將用戶重定向到患者頁面?
謝謝你先進的支持
我最終啟用了WebRTC javascript插件,以啟用在手機上使用相機的面板。 (本教程https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Taking_still_photos#Using_specific_devices )
然后使用此示例啟用后置攝像頭,因為第一部分僅允許使用前置攝像頭。 ( https://webrtc.github.io/samples/src/content/devices/input-output/ )
這給了我想象的圖像捕獲所需的結果。
然后我使用ZXing創建所需的QR,然后再讀取WebRTC攝像頭捕獲的圖像。
我還記得當我嘗試在我的手機上運行網站時顯示空白屏幕的相機,原來是因為網站沒有驗證SSL證書,這意味着網站仍然是HTTP而不是HTTPS由於某種原因允許移動設備訪問攝像頭功能。 ( https://www.pluralsight.com/guides/visual-studio-2017-resolving-ssl-tls-connections-problems-with-iis-express )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.