使用IRONBARCODE ASP.NET條碼掃描器:文件上傳和REST API與IronBarcode Jordi Bardia 更新:2026年3月1日 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 LLM副本 LLM副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 在ASP.NET中使用IronBarcode進行條碼掃描變得簡單明瞭:通過NuGet安裝,調用BarcodeReader.Read(),並在一個步驟中獲取類型、自信度和位置數據的解碼值——無需複雜配置。 條碼掃描是現代Web應用程式中的標準要求,為庫存管理、文件處理和票務驗證工作流程提供支持。 根據GS1,條碼每天在全球超過60億筆交易中被使用——這一數字凸顯了準確條碼讀取對於任何商業系統的重要性。 ISO/IEC 15415標準定義了2D條碼符號的質量指標,而ISO/IEC 15416標準涵蓋了1D線性條碼,IronBarcode本身支持這兩者。 本指南展示如何使用IronBarcode將可靠的條碼掃描添加到您的ASP.NET Core應用程式中,涵蓋安裝、檔案上傳處理、REST API整合和生產部署模式。 到最後,您將擁有一個同時適用於Razor頁面檔案上傳掃描器和接受來自任何客戶端的Base64編碼圖像的JSON API端點的運作代碼。 如何在ASP.NET項目中安裝IronBarcode? 開始只需幾分鐘。 該程式庫支持ASP.NET Core和傳統的ASP.NET MVC應用程式,使其適用於各種專案類型。Enterprise部署可在Azure、AWS Lambda和Docker容器中同樣有效。 該程式庫的機器學習驅動檢測通過自動應用先進的圖像校正來處理具有挑戰性的條碼圖像,這在以移動相機在可變光照下拍攝的照片特別有用。 通過NuGet包管理器安裝 在Visual Studio中打開包管理器控制台並運行: Install-Package BarCode Install-Package BarCode SHELL 或者,使用.NET CLI: dotnet add package BarCode dotnet add package BarCode SHELL 或在Visual Studio NuGet包管理器UI中搜尋"BarCode"並點擊安裝。 該包會自動管理所有依賴項。 針對特定平台的部署,請考慮使用為目標環境優化的特定平台NuGet包。 該程式庫提供標準和BarCode.Slim包以適應不同的部署場景。 完整的安裝指南請參見IronBarcode安裝指南。 配置您的專案 安裝後,將必要的using語句添加到您的C#文件中: using IronBarCode; using IronBarCode; $vbLabelText $csharpLabel 此導入使您可以訪問IronBarcode的完整條碼讀取和生成功能。 該程式庫支持超過30種條碼格式,包括QR Code, Code 128, Code 39, Data Matrix和PDF417。查看支持的條碼格式的完整列表以確認與您的使用案例的兼容性。 有關解決安裝問題,請參閱NuGet包故障排除指南或提交工程請求以獲得專業支持。 選擇正確的架構模式 在ASP.NET中實現條碼掃描時,您有兩種主要的架構方法。 了解這些模式有助於您為每個使用案例選擇正確的條碼讀取設置: // Server-side processing -- recommended for most ASP.NET scenarios var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, UseConfidenceThreshold = true, ConfidenceThreshold = 0.85 }; var results = BarcodeReader.Read(stream, options); foreach (var barcode in results) { Console.WriteLine($"Type: {barcode.BarcodeType}, Value: {barcode.Text}"); } // Server-side processing -- recommended for most ASP.NET scenarios var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, UseConfidenceThreshold = true, ConfidenceThreshold = 0.85 }; var results = BarcodeReader.Read(stream, options); foreach (var barcode in results) { Console.WriteLine($"Type: {barcode.BarcodeType}, Value: {barcode.Text}"); } $vbLabelText $csharpLabel 服務器端方法為您提供最大控制權的圖像處理,可在所有瀏覽器中一致運作。 當服務器處理每張圖像時,您還可以獲得清晰的審覈軌跡:每個掃描的條碼都經過您的應用程式層,您可以在其中記錄它,與資料庫進行驗證,或觸發下游工作流程。 該模式特別適合於醫療保健、物流和製造等受監管行業,每次掃描都必須被記錄。 對於客戶端相機拍攝整合,現代瀏覽器支持用於相機訪問的MediaDevices API,並可通過REST API與IronBarcode的服務器端處理結合使用——本指南稍後將詳細介紹。選擇服務器端處理還簡化了您的安全模型:沒有敏感的處理邏輯暴露給瀏覽器,所有驗證都發生在您的應用程式邊界內。 客戶端與服務器端條碼掃描權衡 方面 客戶端捕獲+服務器處理 純服務器端處理 最佳適用於 與相機的即時掃描 批量處理,文件上傳 瀏覽器支持 僅支持現代瀏覽器 所有瀏覽器 用戶體驗 即時反饋 標準上傳流程 安全模型 更複雜(CORS, 認證) 簡單明瞭 帶寬使用 較低(設備上預處理) 較高(原始圖像上傳) 如何實現文件上傳條碼掃描? 文件上傳掃描是ASP.NET Web應用程式中最常見的條碼案例。 該模式適用於處理發票、運單或任何帶有嵌入條碼的文件。 為了提高吞吐量,考慮實現異步條碼讀取以同時處理多次上傳。 構建上傳表單 在您的ASP.NET視圖中創建一個響應式HTML表單: @* Razor view -- barcode upload form *@ <form method="post" enctype="multipart/form-data" id="barcodeForm"> <div class="form-group"> <label for="barcodeFile">Select Barcode Image:</label> <input type="file" name="barcodeFile" id="barcodeFile" accept="image/*,.pdf" class="form-control" capture="environment" /> </div> <button type="submit" class="btn btn-primary" id="scanBtn"> <span class="spinner-border spinner-border-sm d-none" role="status"></span> Scan Barcode </button> </form> <div id="results"> @ViewBag.BarcodeResult </div> @* Razor view -- barcode upload form *@ <form method="post" enctype="multipart/form-data" id="barcodeForm"> <div class="form-group"> <label for="barcodeFile">Select Barcode Image:</label> <input type="file" name="barcodeFile" id="barcodeFile" accept="image/*,.pdf" class="form-control" capture="environment" /> </div> <button type="submit" class="btn btn-primary" id="scanBtn"> <span class="spinner-border spinner-border-sm d-none" role="status"></span> Scan Barcode </button> </form> <div id="results"> @ViewBag.BarcodeResult </div> $vbLabelText $csharpLabel 在移動設備上啟用後置相機,使用者可在無需JavaScript的情況下獲得原生相機體驗。 實現安全的後端處理 控制器操作處理文件驗證、記憶體流處理和結果格式化: [HttpPost] [ValidateAntiForgeryToken] [RequestSizeLimit(10_000_000)] // 10MB limit public async Task<IActionResult> ScanBarcode(IFormFile barcodeFile) { var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".pdf" }; var extension = Path.GetExtension(barcodeFile.FileName).ToLowerInvariant(); if (!allowedExtensions.Contains(extension)) { ModelState.AddModelError("", "Invalid file type"); return View(); } if (barcodeFile != null && barcodeFile.Length > 0) { using var stream = new MemoryStream(); await barcodeFile.CopyToAsync(stream); stream.Position = 0; var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional | BarcodeEncoding.QRCode | BarcodeEncoding.DataMatrix, ImageFilters = new ImageFilterCollection { new SharpenFilter(), new ContrastFilter() } }; var results = BarcodeReader.Read(stream, options); ViewBag.BarcodeResult = results.Any() ? string.Join("<br/>", results.Select(r => $"<strong>{r.BarcodeType}:</strong> {r.Text}")) : "No barcodes found in the image."; } return View(); } [HttpPost] [ValidateAntiForgeryToken] [RequestSizeLimit(10_000_000)] // 10MB limit public async Task<IActionResult> ScanBarcode(IFormFile barcodeFile) { var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff", ".bmp", ".pdf" }; var extension = Path.GetExtension(barcodeFile.FileName).ToLowerInvariant(); if (!allowedExtensions.Contains(extension)) { ModelState.AddModelError("", "Invalid file type"); return View(); } if (barcodeFile != null && barcodeFile.Length > 0) { using var stream = new MemoryStream(); await barcodeFile.CopyToAsync(stream); stream.Position = 0; var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional | BarcodeEncoding.QRCode | BarcodeEncoding.DataMatrix, ImageFilters = new ImageFilterCollection { new SharpenFilter(), new ContrastFilter() } }; var results = BarcodeReader.Read(stream, options); ViewBag.BarcodeResult = results.Any() ? string.Join("<br/>", results.Select(r => $"<strong>{r.BarcodeType}:</strong> {r.Text}")) : "No barcodes found in the image."; } return View(); } $vbLabelText $csharpLabel 該實現驗證文件類型後再進行處理,從記憶體流中讀取條碼,並返回所有檢測到的結果。 IronBarcode處理多種圖像格式,包括多頁TIFF和GIF和PDF文件,消除了格式特定的處理代碼。 掃描的輸入和輸出是什麼樣子的 碼128條碼編碼URL 'https://ironsoftware.com/csharp/barcode/',顯示機器可讀的線條和人類可讀的底部文本,以便在ASP.NET條碼讀取應用程式中進行準確掃描。 上面的例子顯示了一個標準的Code 128條碼——它是運輸和庫存應用中的常見格式。 掃描後,結果屏幕確認解碼值以及自信度的元數據: ASP.NET Core Web應用程式界面顯示成功的條碼掃描結果,文件上傳表單顯示解碼的Code128條碼值和自信分數元數據。 IronBarcode返回條碼類型,解碼值,自信分數,以及每個上傳圖像中檢測到的條碼的位置信息。 如何構建條碼掃描的REST API? 現代ASP.NET應用程式通常通過REST API暴露條碼掃描功能,允許與移動應用、單頁應用或第三方服務進行整合。 該模式支持客戶端相機捕獲與服務器端處理。 條碼API的安全注意事項 在撰寫控制器之前,請規劃安全層。 條碼數據能夠包含任意內容,因此始終驗證輸入。 請通過IronBarcode安全指導方針獲得完整保護: 輸入驗證:在存儲或操作前淨化條碼內容 速率限制:使用ASP.NET Core內建的速率限制中間件來防止API濫用 驗證:使用JWT令牌或API金鑰保護端點 強制HTTPS:所有條碼API流量必須通過TLS傳輸 CORS政策:限制哪些來源可以調用您的掃描端點 License Key管理:正確應用授權金鑰並在web.config中進行配置以供生產使用。 構建生產API控制器 [ApiController] [Route("api/[controller]")] public class BarcodeController : ControllerBase { private readonly ILogger<BarcodeController> _logger; private readonly IMemoryCache _cache; public BarcodeController(ILogger<BarcodeController> logger, IMemoryCache cache) { _logger = logger; _cache = cache; } [HttpPost("scan")] [ProducesResponseType(typeof(BarcodeResponse), 200)] [ProducesResponseType(typeof(ErrorResponse), 400)] public async Task<IActionResult> ScanBarcode([FromBody] BarcodeRequest request) { try { if (string.IsNullOrEmpty(request.ImageBase64)) return BadRequest(new ErrorResponse { Error = "Image data is required" }); var cacheKey = $"barcode_{request.ImageBase64.GetHashCode()}"; if (_cache.TryGetValue(cacheKey, out BarcodeResponse cachedResult)) return Ok(cachedResult); byte[] imageBytes = Convert.FromBase64String(request.ImageBase64); if (imageBytes.Length > 10 * 1024 * 1024) return BadRequest(new ErrorResponse { Error = "Image size exceeds 10MB limit" }); var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Faster, ExpectMultipleBarcodes = request.ExpectMultiple ?? false, UseConfidenceThreshold = true, ConfidenceThreshold = 0.8 }; var results = await Task.Run(() => BarcodeReader.Read(imageBytes, options)); var response = new BarcodeResponse { Success = true, Barcodes = results.Select(r => new BarcodeData { Type = r.BarcodeType.ToString(), Value = r.Text, Confidence = r.Confidence, Position = new BarcodePosition { X = r.Points.Select(p => p.X).Min(), Y = r.Points.Select(p => p.Y).Min(), Width = r.Width, Height = r.Height } }).ToList() }; _cache.Set(cacheKey, response, TimeSpan.FromMinutes(5)); return Ok(response); } catch (FormatException) { return BadRequest(new ErrorResponse { Error = "Invalid base64 image data" }); } catch (Exception ex) { _logger.LogError(ex, "Error processing barcode scan"); return StatusCode(500, new ErrorResponse { Error = "Internal server error" }); } } } public record BarcodeRequest(string ImageBase64, bool? ExpectMultiple); public record BarcodeResponse { public bool Success { get; init; } public List<BarcodeData> Barcodes { get; init; } = new(); } public record BarcodeData { public string Type { get; init; } public string Value { get; init; } public double Confidence { get; init; } public BarcodePosition Position { get; init; } } public record BarcodePosition(int X, int Y, int Width, int Height); public record ErrorResponse { public bool Success => false; public string Error { get; init; } } [ApiController] [Route("api/[controller]")] public class BarcodeController : ControllerBase { private readonly ILogger<BarcodeController> _logger; private readonly IMemoryCache _cache; public BarcodeController(ILogger<BarcodeController> logger, IMemoryCache cache) { _logger = logger; _cache = cache; } [HttpPost("scan")] [ProducesResponseType(typeof(BarcodeResponse), 200)] [ProducesResponseType(typeof(ErrorResponse), 400)] public async Task<IActionResult> ScanBarcode([FromBody] BarcodeRequest request) { try { if (string.IsNullOrEmpty(request.ImageBase64)) return BadRequest(new ErrorResponse { Error = "Image data is required" }); var cacheKey = $"barcode_{request.ImageBase64.GetHashCode()}"; if (_cache.TryGetValue(cacheKey, out BarcodeResponse cachedResult)) return Ok(cachedResult); byte[] imageBytes = Convert.FromBase64String(request.ImageBase64); if (imageBytes.Length > 10 * 1024 * 1024) return BadRequest(new ErrorResponse { Error = "Image size exceeds 10MB limit" }); var options = new BarcodeReaderOptions { Speed = ReadingSpeed.Faster, ExpectMultipleBarcodes = request.ExpectMultiple ?? false, UseConfidenceThreshold = true, ConfidenceThreshold = 0.8 }; var results = await Task.Run(() => BarcodeReader.Read(imageBytes, options)); var response = new BarcodeResponse { Success = true, Barcodes = results.Select(r => new BarcodeData { Type = r.BarcodeType.ToString(), Value = r.Text, Confidence = r.Confidence, Position = new BarcodePosition { X = r.Points.Select(p => p.X).Min(), Y = r.Points.Select(p => p.Y).Min(), Width = r.Width, Height = r.Height } }).ToList() }; _cache.Set(cacheKey, response, TimeSpan.FromMinutes(5)); return Ok(response); } catch (FormatException) { return BadRequest(new ErrorResponse { Error = "Invalid base64 image data" }); } catch (Exception ex) { _logger.LogError(ex, "Error processing barcode scan"); return StatusCode(500, new ErrorResponse { Error = "Internal server error" }); } } } public record BarcodeRequest(string ImageBase64, bool? ExpectMultiple); public record BarcodeResponse { public bool Success { get; init; } public List<BarcodeData> Barcodes { get; init; } = new(); } public record BarcodeData { public string Type { get; init; } public string Value { get; init; } public double Confidence { get; init; } public BarcodePosition Position { get; init; } } public record BarcodePosition(int X, int Y, int Width, int Height); public record ErrorResponse { public bool Success => false; public string Error { get; init; } } $vbLabelText $csharpLabel 此端點接受Base64編碼的圖像——標準的圖像通過HTTP傳輸格式。 回應包括條碼類型、解碼值、置信度分數和位置。 對於高容量場景,請查看批量條碼處理和讀取速度優化選項。 API如何處理多個條碼? 三種不同條碼格式(標記為ABC)展示了IronBarcode在生產環境中同時處理QR Code, Code128和DataMatrix符號。 IronBarcode通過一個調用處理單個圖像中的多個條碼,返回一個結果數組。 回應中的每個條目都包括位置信息,因此客戶端應用程式可以在屏幕上高亮檢測到的條碼。 瀏覽器開發者工具網絡標籤顯示成功的JSON API回應,包含三個檢測到的條碼的數組,完整的元數據包括類型、值、置信度和位置坐標。 結構化的JSON回應為客戶端應用程式提供了一切所需,以處理和顯示條碼結果,而無需額外查詢。 如何處理具有挑戰性的條碼圖像? 現實世界的條碼掃描經常涉及不完美的圖像——以角度拍攝的照片、光照不足或部分損壞的條碼。 IronBarcode通過其先進的圖像處理功能和機器學習置信度閾值解決這些場景。 診斷常見的掃描問題 在應用校正之前,首先確定您的問題屬於哪個類別。 生產中的掃描失敗大多落入五大類之一:圖像質量問題(模糊、噪聲、低分辨率)、幾何問題(旋轉、傾斜、透視畸變)、損壞問題(撕裂標籤、墨水模糊)、環境問題(眩光、陰影、不一致的光線),以及誤報檢測,這是指讀取器找到了不存在的條碼。 了解類別有助於您選擇正確的過濾器組合和讀取速度,而不必對每個圖像進行不必要的處理。 對於大多數Web應用程式場景,從AutoRotate = true開始可以涵蓋大多數案例。 只有當第一次傳回沒有結果時,才升級到ExtremeDetail。 下面的多層策略代码實現了這種分層策略。 快速第一次通過快速處理典型圖像,讓常見情况下的中位數延遲保持在較低水準。 當第一次通過失败时,會触发详细的第二次通过,确保在实际需要时才承担额外的处理成本。 此模式使您的ASP.NET端點在正常負載下保持響應,同時仍可靠地處理困難的邊緣案例。 常见條碼掃描問題和解決方案 問題 症狀 解決方案 模糊的圖像 低置信度分數,遺漏讀取 應用`SharpenFilter`,增加`ExtremeDetail`速度 旋轉的條碼 條碼完全未檢測到 啟用`AutoRotate = true` 受損的條碼 局部讀取,錯誤的值 啟用錯誤校正,使用`RemoveFalsePositive` 反差差 檢測不一致 應用`ContrastFilter`和`BrightnessFilter` 性能太慢 上傳高延遲 使用`ReadingSpeed.Faster`,啟用多線程 實現多層圖像處理 對於具挑戰性的圖像,分層處理方法可在不損失性能於簡易圖像的情況下獲得最佳效果: public class AdvancedBarcodeProcessor { private readonly ILogger<AdvancedBarcodeProcessor> _logger; public async Task<List<ScannedBarcode>> ProcessChallengingImage(Stream imageStream) { // First pass -- fast, minimal processing var fastOptions = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, AutoRotate = false, UseConfidenceThreshold = true, ConfidenceThreshold = 0.85 }; var results = BarcodeReader.Read(imageStream, fastOptions); if (!results.Any()) { // Second pass -- aggressive image correction imageStream.Position = 0; var detailedOptions = new BarcodeReaderOptions { Speed = ReadingSpeed.ExtremeDetail, ExpectMultipleBarcodes = true, AutoRotate = true, RemoveFalsePositive = true, UseConfidenceThreshold = true, ConfidenceThreshold = 0.6, Multithreaded = true, ExpectBarcodeTypes = BarcodeEncoding.All, ImageFilters = new ImageFilterCollection { new SharpenFilter(2.5f), new ContrastFilter(2.0f), new BrightnessFilter(1.2f), new InvertFilter() } }; results = BarcodeReader.Read(imageStream, detailedOptions); _logger.LogInformation("Second pass detected {Count} barcodes", results.Count()); } return results.Select(r => new ScannedBarcode { Value = r.Text, BarcodeType = r.BarcodeType.ToString(), Confidence = r.Confidence, RotationAngle = r.RotationAngle, PageNumber = r.PageNumber }).ToList(); } } public record ScannedBarcode { public string Value { get; init; } public string BarcodeType { get; init; } public double Confidence { get; init; } public float RotationAngle { get; init; } public int PageNumber { get; init; } } public class AdvancedBarcodeProcessor { private readonly ILogger<AdvancedBarcodeProcessor> _logger; public async Task<List<ScannedBarcode>> ProcessChallengingImage(Stream imageStream) { // First pass -- fast, minimal processing var fastOptions = new BarcodeReaderOptions { Speed = ReadingSpeed.Balanced, ExpectMultipleBarcodes = true, AutoRotate = false, UseConfidenceThreshold = true, ConfidenceThreshold = 0.85 }; var results = BarcodeReader.Read(imageStream, fastOptions); if (!results.Any()) { // Second pass -- aggressive image correction imageStream.Position = 0; var detailedOptions = new BarcodeReaderOptions { Speed = ReadingSpeed.ExtremeDetail, ExpectMultipleBarcodes = true, AutoRotate = true, RemoveFalsePositive = true, UseConfidenceThreshold = true, ConfidenceThreshold = 0.6, Multithreaded = true, ExpectBarcodeTypes = BarcodeEncoding.All, ImageFilters = new ImageFilterCollection { new SharpenFilter(2.5f), new ContrastFilter(2.0f), new BrightnessFilter(1.2f), new InvertFilter() } }; results = BarcodeReader.Read(imageStream, detailedOptions); _logger.LogInformation("Second pass detected {Count} barcodes", results.Count()); } return results.Select(r => new ScannedBarcode { Value = r.Text, BarcodeType = r.BarcodeType.ToString(), Confidence = r.Confidence, RotationAngle = r.RotationAngle, PageNumber = r.PageNumber }).ToList(); } } public record ScannedBarcode { public string Value { get; init; } public string BarcodeType { get; init; } public double Confidence { get; init; } public float RotationAngle { get; init; } public int PageNumber { get; init; } } $vbLabelText $csharpLabel BarcodeReaderOptions類提供了對掃描每個方面的細粒度控制。 設置AutoRotate可以處理任何角度捕獲的圖像,而圖像過濾器可以改善模糊或低對比度條碼的清晰度。 有關詳細配置,請參見條碼讀取設置示例和PDF專用讀取設置。 在處理PDF時,考慮將條碼蓋章在PDF上或將條碼創建為PDF文件。 對於高容量處理,通過異步和多線程功能可以顯著提高吞吐量。 添加瀏覽器兼容性和後備策略 支持多樣的瀏覽器需要進步增強。 Android和桌面Chrome、Edge和Firefox上的現代瀏覽器支持用於相機訪問的MediaDevices.getUserMedia() API。 iOS上的Safari從版本11開始支持它。 較舊的企業瀏覽器、IE11兼容模式和某些鎖定的企業環境可能根本不支持相機訪問,因此您考慮的後備文件上傳路徑必須始終保持可用。 推薦的方法是在運行時使用功能檢測而不是用戶代理嗅探,然後根據需要顯示或隱藏相機界面。 從支持相機的界面開始,並優雅地回退到檔案上傳: @* Razor view with progressive enhancement *@ <div class="barcode-scanner-container"> @* Camera capture -- hidden until JavaScript confirms support *@ <div id="cameraSection" class="d-none"> <video id="videoPreview" class="w-100" autoplay></video> <button id="captureBtn" class="btn btn-primary mt-2">Capture and Scan</button> </div> @* File upload -- always available as fallback *@ <div id="uploadSection"> <form method="post" enctype="multipart/form-data" asp-action="ScanBarcode" asp-controller="Barcode"> <div class="form-group"> <label>Upload Barcode Image:</label> <input type="file" name="file" accept="image/*,.pdf" class="form-control" required /> </div> <button type="submit" class="btn btn-primary">Upload and Scan</button> </form> </div> </div> @* Razor view with progressive enhancement *@ <div class="barcode-scanner-container"> @* Camera capture -- hidden until JavaScript confirms support *@ <div id="cameraSection" class="d-none"> <video id="videoPreview" class="w-100" autoplay></video> <button id="captureBtn" class="btn btn-primary mt-2">Capture and Scan</button> </div> @* File upload -- always available as fallback *@ <div id="uploadSection"> <form method="post" enctype="multipart/form-data" asp-action="ScanBarcode" asp-controller="Barcode"> <div class="form-group"> <label>Upload Barcode Image:</label> <input type="file" name="file" accept="image/*,.pdf" class="form-control" required /> </div> <button type="submit" class="btn btn-primary">Upload and Scan</button> </form> </div> </div> $vbLabelText $csharpLabel 如果您偏愛基於元件的方法,Blazor整合提供最小配置的現代Web應用程式支持。 有關部署故障排除,請參閱運行時副本異常指南。 你的下一步行動是什麼? 在ASP.NET中使用IronBarcode進行條碼掃描變得簡單。 您只需安裝一個NuGet包,調用BarcodeReader.Read(),即可獲得可靠的解碼結果,適用於30多種格式——包括其他程式庫難以處理的現實世界圖像。 要繼續建立在此基礎上,請探索以下資源: 讀取條碼教程——使用於所有掃描場景的詳細指南 條碼生成——程式化創建條碼和QR碼 QR Code生成器——特定QR碼功能和樣式 圖像校正——提高難度圖片掃描準確度的技術 異步和多線程——可對高流量應用程式中的條碼處理進行擴展 跨平台兼容性——可部署在Windows、Linux、Docker、Azure和AWS上 支持的條碼格式——可讀寫符號完整列表 容錯功能——在惡劣條件下的可靠運作 API參考——所有類別和選項的完整文件 授權選項——生產部署用的SaaS、OEM和企業授權 開始使用免費試用授權,以在ASP.NET應用程式中測試IronBarcode,無限制。 試用版提供對所有功能的完全訪問,包括多格式檢測、圖像校正和本指南中展示的REST API模式——以便您在承擔實際商業授權前評估圖片性能。 對於需要在裝置上掃描的.NET MAUI移动應用程式,請參閱延伸至iOS和Android目標的.NET MAUI條碼掃描教學。 常見問題解答 條碼掃描在 ASP.NET 應用程式中的主要用途是什麼? 條碼掃描在 ASP.NET 應用程式中的主要用於增強庫存管理系統、在活動中處理門票和數字化紙質文件,從而提高效率並減少錯誤。 IronBarcode 如何促進 ASP.NET 中的條碼掃描? IronBarcode 通過提供可以輕鬆集成到網頁應用程式中的可靠且高效的組件,簡化了 ASP.NET 中的條碼掃描過程,允許開發者快速實現掃描功能。 IronBarcode 可以掃描哪些類型的條碼? IronBarcode 支持掃描多種條碼格式,包括傳統的線性條碼和現代的二維條碼,確保與多樣化的應用程序兼容。 IronBarcode 能否處理文件處理的條碼掃描? 是的,IronBarcode 非常適合文件處理工作流程,可以用來掃描嵌入的條碼以數字化和組織紙質文件。 IronBarcode 是否適合庫存管理系統? IronBarcode 是庫存管理系統的極佳選擇,因為它可以通過掃描條碼來高效跟踪產品,從而簡化操作並減少錯誤。 集成 IronBarcode 如何改善活動門票處理? 通過集成 IronBarcode,活動門票處理變得無縫,因為它允許快速掃描門票條碼,從而促進事件中快速準確的入場管理。 在 ASP.NET 專案中使用 IronBarcode 有哪些優勢? 在 ASP.NET 專案中使用 IronBarcode 提供了多種優勢,包括易於集成、多條碼格式支持,以及增強的應用程式性能,從而為條碼掃描需求提供了強大的解決方案。 實施 IronBarcode 是否需要廣泛的編碼知識? 不,IronBarcode 的設計以開發者為導向,使得在 ASP.NET 應用程式中實現條碼掃描功能變得簡單,僅需最低限度的編碼知識。 IronBarcode 能否用於移動網頁應用程式? 是的,IronBarcode 可以集成到移動網頁應用程式中,允許隨時隨地的條碼掃描,提升了 ASP.NET 專案的多功能性。 Jordi Bardia 立即與工程團隊聊天 軟體工程師 Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担產品测测试,產品開發和研究的责任時,Jordi 為持续的產品改進增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。 相關文章 發表日期 2026年3月8日 創建.NET應用程式的條碼專業SDK 全面的.NET條碼SDK,用於QR Codes、GS1、Data Matrix等。支持.NET 6-10、Core和Framework。 閱讀更多 發表日期 2026年3月8日 構建Barcode SDK C#:通過一個程式庫生成、讀取和掃描條碼 在C#中使用IronBarcode構建條碼SDK功能。生成條碼圖像,從文件掃描多個條碼,並使用一個.NET程式庫讀取QR Code。包含範例代碼。 閱讀更多 更新2026年3月1日 VB .NET條碼字體:如何在沒有字體依賴的情況下生成和列印條碼 在VB.NET中以現代方式處理條碼字體。使用IronBarcode生成Code 39和Code 128條碼圖像-無字體依賴。提供免費試用。 閱讀更多 使用現代C#掃描程式庫創建和讀取Xamarin條碼圖像C# USB條碼掃描器:構建完...
發表日期 2026年3月8日 創建.NET應用程式的條碼專業SDK 全面的.NET條碼SDK,用於QR Codes、GS1、Data Matrix等。支持.NET 6-10、Core和Framework。 閱讀更多
發表日期 2026年3月8日 構建Barcode SDK C#:通過一個程式庫生成、讀取和掃描條碼 在C#中使用IronBarcode構建條碼SDK功能。生成條碼圖像,從文件掃描多個條碼,並使用一個.NET程式庫讀取QR Code。包含範例代碼。 閱讀更多
更新2026年3月1日 VB .NET條碼字體:如何在沒有字體依賴的情況下生成和列印條碼 在VB.NET中以現代方式處理條碼字體。使用IronBarcode生成Code 39和Code 128條碼圖像-無字體依賴。提供免費試用。 閱讀更多