IRONSOFTWAREHOME
條碼網路掃描器
using IronBarCode;

public string ReadBarCode(CamImage imageData)
{
        // Decode the base64 image data
        var splitObject = imageData.imageDataBase64.Split(',');
        byte[] imagebyteData = Convert.FromBase64String((splitObject.Length > 1) ? splitObject[1] : splitObject[0]);

        using (var ms = new MemoryStream(imagebyteData))
        {
            // Convert byte array to Image
            Image barcodeImage = Image.FromStream(ms);

            // Read barcode from Image
            var results = BarcodeReader.Read(barcodeImage);

	        // Read first value from barcode
            return $"{DateTime.Now}: Barcode is ({results[0].Value})";
        }

}
Imports IronBarCode

Public Function ReadBarCode(imageData As CamImage) As String
    ' Decode the base64 image data
    Dim splitObject = imageData.imageDataBase64.Split(","c)
    Dim imagebyteData As Byte() = Convert.FromBase64String(If(splitObject.Length > 1, splitObject(1), splitObject(0)))

    Using ms As New MemoryStream(imagebyteData)
        ' Convert byte array to Image
        Dim barcodeImage As Image = Image.FromStream(ms)

        ' Read barcode from Image
        Dim results = BarcodeReader.Read(barcodeImage)

        ' Read first value from barcode
        Return $"{DateTime.Now}: Barcode is ({results(0).Value})"
    End Using

End Function
NuGet Download
PM > Install-Package BarCode
條碼網路掃描器

條碼網路掃描器

從網路來源掃描條碼通常需要將影像資料處理為文字字串,而非實體檔案。 這種方法的主要優勢在於它允許您的應用程式直接處理來自使用者上傳或網路攝影機提供的影像,而無需首先保存到磁碟。

在此程式碼範例中,我們將展示主要的程式碼片段,展示如何將Base64字串轉換回圖像,並在與Blazor等網路平台整合時使用IronBarcode掃描資料。

設置IronBarcode網路掃描器的5步指南

  • byte[] imagebyteData = Convert.FromBase64String((splitObject.Length > 1) ? splitObject[1] : splitObject[0]);
  • using (var ms = new MemoryStream(imagebyteData))
  • Image barcodeImage = Image.FromStream(ms);
  • var results = BarcodeReader.Read(barcodeImage);
  • return $"{DateTime.Now}: Barcode is ({results[0].Value})";

程式碼解釋

首先,輸入字串,通常是一個MemoryStream。 此外,會進行檢查以確定字串是否需要拆分。 這處理了輸入可能包含標頭的情況,如資料URI,確保只處理實際的影像資料。

接著,這些位元組會載入到MemoryStream中。 這充當暫時的容器,允許從流中使用Image物件。 一旦圖像載入,就會傳遞給BarcodeReader.Read進行掃描。

最後,會返回讀取結果和時間戳。通過存取包含Value屬性。

了解更多關於使用IronBarcode建立網路掃描器的資訊!

準備好開始了嗎?

Nuget Downloads 2,422,100版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費即時演示
Booking Badge

全球數百萬工程師信賴

Iron Software的客戶標誌
獲取您的無義務諮詢
完成下方表單或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
全球數百萬工程師信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立