QR码在Asp.net Web应用程序中扫描并使用c#拍摄图片选项#
问题描述:
我需要开发一个Web应用程序,它需要扫描QR码并阅读它的内容。QR码在Asp.net Web应用程序中扫描并使用c#拍摄图片选项#
Asp.net Web应用程序可以使用,后面使用的代码是C#。
是否可以拍照,并在Web应用程序
答
使用C#.NET保存它您可以在浏览器客户端的图片。将图像数据发送到c#页面。
<input id="upload" name="upload" type="file" accept="image/*" />
它只是一个html文件输入,当选择或相机收到图像时,您可以获取QR图像数据。
$("#upload").on('change', function() {
var file = $(this)[0].files[0];
if(!file) {//undefined
return;
}
if(!startLoading()) {
return;
}
var file = $(this)[0].files[0];
var reader = new FileReader();
reader.readAsDataURL(file); // read file as Data URL
reader.onload = function() {
var base64 = this.result;
//send this base64 string to c# backend page using ajax
...
});
然后代码在你的c#页面,得到base64字符串,改为图像。
byte[] arr2 = Convert.FromBase64String(base64);
using (MemoryStream ms2 = new MemoryStream(arr2))
{
System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(ms2);
bmp2.Save(filePath + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
...