【问题标题】:How to scan the barcode image using ZXing in mvc?如何在 mvc 中使用 ZXing 扫描条码图像?
【发布时间】:2018-07-16 12:40:42
【问题描述】:

我尝试使用图像扫描条形码图像并将条形码编号粘贴到文本框中

[HttpPost]
public ActionResult ScanDetail( Scaner Scanning)
{
    IBarcodeReader reader = new BarcodeReader();

    // load a bitmap    
    var barcodeBitmap = (Bitmap)Image.LoadFrom("C:\\sample-barcode-image.png");

    // detect and decode the barcode inside the bitmap
    var result = reader.Decode(barcodeBitmap);

    // do something with the result
    if (result != null)
    {
        Scanning.ScanType = result.BarcodeFormat.ToString();
        Scanning.ScanContent = result.Text;   
    }

    return View();
}

我在 LoadForm 中收到错误

错误:“图像”不包含 LoadForm 的定义。

Ajax 调用:

<script type="text/javascript">
    $("#BtnScan").click(function () {

        var ScanType = $('#ScanType').val();
        var ScanContent = $('#ScanContent').val();
       $.ajax({
            url: "@Url.Action("ScanDetail", "Home")",
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            data: JSON.stringify({
                ScanType: $("#ScanType").val(),
                ScanContent: $("#ScanContent").val()
            }),
            async: false
        });
    });
</script>

【问题讨论】:

    标签: javascript ajax asp.net-mvc zxing barcode-scanner


    【解决方案1】:

    我解决了,也许某个地方的人会有用。

    Scaner.cs

        public string ScanContent { get; set; }
        public string ScanType { get; set; }
    

    Home Controller.cs

     [HttpPost]
        public ActionResult ScanDetail(Scaner Scanning)
        {
            IBarcodeReader reader = new BarcodeReader();
    
    
            using (Bitmap oldBmp = new Bitmap("E:\\barcodeQR.jpg"))
            using (Bitmap newBmp = new Bitmap(oldBmp))
            using (Bitmap targetBmp = newBmp.Clone(new Rectangle(0, 0, newBmp.Width, newBmp.Height), PixelFormat.Format32bppArgb))
            {
                // targetBmp is now in the desired format.
                var barcodeBitmap = (targetBmp);
                var result = reader.Decode(barcodeBitmap);
                // do something with the result
                if (result != null)
                {
                    Scanning.ScanType = result.BarcodeFormat.ToString();
                    Scanning.ScanContent = result.Text;
    
                }
    
            }
            return View();
        }
    

    它返回扫描类型和扫描内容。 谢谢

    【讨论】:

      【解决方案2】:
      var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png");
      

      【讨论】:

        猜你喜欢
        • 2020-03-13
        • 1970-01-01
        • 1970-01-01
        • 2021-04-05
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多