我目前正在从事一个由患者数据库组成的医疗项目。每次将患者添加到记录中并且QR码包含患者的ID时,我都会使用zxing生成QR码。
生成代码如下
//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";
}
Run Code Online (Sandbox Code Playgroud)
然后在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;
}
}
Run Code Online (Sandbox Code Playgroud)
我用于移动用户打开相机的方法如下:
<p class="lead" style="text-align: center"><input class="btn btn-success btn-sm" type="file" accept="image/*" runat="server" capture="camera" /></p>
Run Code Online (Sandbox Code Playgroud)
问题在于相机实际上并不是在扫描/拍照,而只是作为镜头。有没有办法让它读取并转换代码以获得患者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)
| 归档时间: |
|
| 查看次数: |
967 次 |
| 最近记录: |