跳至頁尾內容
使用IRONBARCODE

如何構建.NET MAUI條碼掃描器SDK應用程式

.NET MAUI 實現了一個可供 Android、iOS 和 Windows 使用的單一程式碼庫承諾。 挑戰在於您需要整合本機硬體功能如條碼掃描時。 手動橋接相機 API 意味著平台特定配置、條件編譯指令和數小時的除錯過程。 有一條更快的路徑。

本教學將向您展示如何使用 IronBarcode 在 .NET MAUI 中構建一個工作中的跨平台條碼掃描器。 您將設置專案、配置平台許可權、從圖像檔案掃描條碼、從 PDF 文件讀取條碼,並通過掃描選項處理多種符號學 - 所有這些都能運行在任何受支持目標上的程式碼中。

開始免費試用並按照以下步驟進行。

NuGet 使用NuGet安裝

PM >  Install-Package BarCode

查看在NuGet上的https://www.nuget.org/packages/BarCode,快速安裝。超過1000萬次下載,正在用C#轉變PDF開發。 您也可以下載DLL

如何在 .NET MAUI 中設置條碼掃描器 SDK?

設置 .NET MAUI 條碼掃描器 SDK 需要建立一個新專案、安裝 NuGet 套件,並配置平台許可權。 整個配置過程在 Visual Studio 中僅需幾分鐘。

建立 .NET MAUI 專案

開啟 Visual Studio 並建立一個新的 .NET MAUI App 專案。 將專案命名為類似 "BarcodeScanner" 描述性的名稱,且選擇 .NET 8 或更高版本作為目標框架。 Visual Studio 會生成具有 Android 和 iOS 平台特定資料夾的預設專案結構。

如果您針對 .NET 10,仍然可使用相同的專案模板。 在您的 .csproj 檔案中更新 <TargetFrameworks> 屬性以包括 net10.0-iosnet10.0-windows10.0.19041.0。 請參閱 .NET MAUI 支持的平台文件獲取完整的目標框架標識符列和最低作業系統版本要求。

安裝IronBarcode

使用套件管理器主控台安裝 IronBarcode NuGet 套件

Install-Package BarCode

此命令將下載並安裝條碼掃描器 SDK 以及所有 .NET MAUI 應用程式所需的依賴項。

配置平台許可權

即使從圖像文件而不是實時相機源進行掃瞄,配置以下許可權是良好做法。

對於 Android,將以下內容新增到 Platforms/Android/AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
XML

對於 iOS,將這些條目新增到 Platforms/iOS/Info.plist

<key>NSPhotoLibraryUsageDescription</key>
<string>Access needed to select barcode images for scanning.</string>
<key>NSCameraUsageDescription</key>
<string>Camera permission for barcode scanning.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Access needed to select barcode images for scanning.</string>
<key>NSCameraUsageDescription</key>
<string>Camera permission for barcode scanning.</string>
XML

初始化 SDK

在應用程式生命週期的早期設置您的授權金鑰以確保 IronBarcode 在進行任何掃描呼叫之前完全啟用。 將啟動放置在 MauiProgram.cs

using IronBarCode;

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
    });

// Activate IronBarcode before the app starts
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";

return builder.Build();
using IronBarCode;

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiApp<App>()
    .ConfigureFonts(fonts =>
    {
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
    });

// Activate IronBarcode before the app starts
License.LicenseKey = "YOUR_LICENSE_KEY_HERE";

return builder.Build();
Imports IronBarCode

Dim builder = MauiApp.CreateBuilder()
builder _
    .UseMauiApp(Of App)() _
    .ConfigureFonts(Sub(fonts)
        fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular")
    End Sub)

' Activate IronBarcode before the app starts
License.LicenseKey = "YOUR_LICENSE_KEY_HERE"

Return builder.Build()
$vbLabelText   $csharpLabel

IronBarcode 提供 免費試用授權以供開發和測試。 在啟動時設置金鑰;在同一進程中,對BarcodeWriter的所有後續呼叫都將使用已激活的授權。

如何從圖像文件讀取條碼?

任何 MAUI 條碼掃描器的核心功能都是從選定的圖像中讀取條碼。 方法 BarcodeReader.Read() 接受一個文件路徑並返回 BarcodeResult 物件的集合,每個偵測到的條碼都有一個物件。

設計使用者介面

MainPage.xaml 中建立一個乾淨的介面,允許使用者選擇圖像文件並查看掃描的條碼資料:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BarcodeScanner.MainPage">
    <VerticalStackLayout Padding="20" Spacing="15">
        <Label Text=".NET MAUI Barcode Scanner" FontSize="24" HorizontalOptions="Center"/>
        <Button Text="Select Image to Scan" Clicked="OnSelectImageClicked"/>
        <Image x:Name="SelectedImageView" HeightRequest="200"/>
        <Label x:Name="ResultLabel" FontSize="16"/>
    </VerticalStackLayout>
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="BarcodeScanner.MainPage">
    <VerticalStackLayout Padding="20" Spacing="15">
        <Label Text=".NET MAUI Barcode Scanner" FontSize="24" HorizontalOptions="Center"/>
        <Button Text="Select Image to Scan" Clicked="OnSelectImageClicked"/>
        <Image x:Name="SelectedImageView" HeightRequest="200"/>
        <Label x:Name="ResultLabel" FontSize="16"/>
    </VerticalStackLayout>
</ContentPage>
XML

實施條碼掃描

將掃描邏輯新增到 MainPage.xaml.cs。 此程式碼通過 MAUI FilePicker API 處理圖像選擇,並將所選文件路徑傳遞給 IronBarcode:

using IronBarCode;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private async void OnSelectImageClicked(object sender, EventArgs e)
    {
        var result = await FilePicker.PickAsync(new PickOptions
        {
            FileTypes = FilePickerFileType.Images,
            PickerTitle = "Select a barcode image"
        });

        if (result != null)
        {
            // Display the selected image
            SelectedImageView.Source = ImageSource.FromFile(result.FullPath);

            // Read barcodes from the image file
            var barcodes = BarcodeReader.Read(result.FullPath);

            ResultLabel.Text = barcodes.Any()
                ? $"Found: {barcodes.First().Value}"
                : "No barcodes detected in selected image.";
        }
    }
}
using IronBarCode;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private async void OnSelectImageClicked(object sender, EventArgs e)
    {
        var result = await FilePicker.PickAsync(new PickOptions
        {
            FileTypes = FilePickerFileType.Images,
            PickerTitle = "Select a barcode image"
        });

        if (result != null)
        {
            // Display the selected image
            SelectedImageView.Source = ImageSource.FromFile(result.FullPath);

            // Read barcodes from the image file
            var barcodes = BarcodeReader.Read(result.FullPath);

            ResultLabel.Text = barcodes.Any()
                ? $"Found: {barcodes.First().Value}"
                : "No barcodes detected in selected image.";
        }
    }
}
Imports IronBarCode

Public Partial Class MainPage
    Inherits ContentPage

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Async Sub OnSelectImageClicked(sender As Object, e As EventArgs)
        Dim result = Await FilePicker.PickAsync(New PickOptions With {
            .FileTypes = FilePickerFileType.Images,
            .PickerTitle = "Select a barcode image"
        })

        If result IsNot Nothing Then
            ' Display the selected image
            SelectedImageView.Source = ImageSource.FromFile(result.FullPath)

            ' Read barcodes from the image file
            Dim barcodes = BarcodeReader.Read(result.FullPath)

            ResultLabel.Text = If(barcodes.Any(), $"Found: {barcodes.First().Value}", "No barcodes detected in selected image.")
        End If
    End Sub
End Class
$vbLabelText   $csharpLabel

輸出

.NET MAUI 條碼掃描器 SDK:在幾分鐘內建立跨平台掃描器:圖像 1 - 掃描條碼輸出

方法 BarcodeReader.Read() 解析選擇的圖像並返回所有檢測到的條碼。 IronBarcode 自動識別多種條碼符號學,包括 QR 程式碼、Code 128、Code 39、EAN-13 和許多其他支持的格式。 結果集合公開了屬性如 PageNumber 以及每個檢測到的程式碼的邊界框坐標。

如何從 PDF 文件掃描條碼?

IronBarcode 能夠區分於許多其他替代方案的是直接從 PDF 文件讀取條碼。 這對於處理文件工作流程的 .NET MAUI 應用程式至關重要 — 發貨單、採購訂單、病歷等類似用例都依賴於嵌入 PDF 的條碼。

方法 BarcodeReader.ReadPdf() 接受文件路徑並返回與圖像讀取器相同的 BarcodeResult 集合,並附加識別每個條碼來源頁面的 PageNumber 屬性:

using IronBarCode;

private async void OnSelectPdfClicked(object sender, EventArgs e)
{
    var result = await FilePicker.PickAsync(new PickOptions
    {
        PickerTitle = "Select a PDF with barcodes"
    });

    if (result != null)
    {
        // Read barcodes from every page of the PDF
        var barcodes = BarcodeReader.ReadPdf(result.FullPath);

        var output = string.Join("\n", barcodes.Select(b =>
            $"Page {b.PageNumber}: [{b.BarcodeType}] {b.Value}"));

        await DisplayAlert("Scan Results", output.Length > 0 ? output : "No barcodes found.", "OK");
    }
}
using IronBarCode;

private async void OnSelectPdfClicked(object sender, EventArgs e)
{
    var result = await FilePicker.PickAsync(new PickOptions
    {
        PickerTitle = "Select a PDF with barcodes"
    });

    if (result != null)
    {
        // Read barcodes from every page of the PDF
        var barcodes = BarcodeReader.ReadPdf(result.FullPath);

        var output = string.Join("\n", barcodes.Select(b =>
            $"Page {b.PageNumber}: [{b.BarcodeType}] {b.Value}"));

        await DisplayAlert("Scan Results", output.Length > 0 ? output : "No barcodes found.", "OK");
    }
}
Imports IronBarCode

Private Async Sub OnSelectPdfClicked(sender As Object, e As EventArgs)
    Dim result = Await FilePicker.PickAsync(New PickOptions With {
        .PickerTitle = "Select a PDF with barcodes"
    })

    If result IsNot Nothing Then
        ' Read barcodes from every page of the PDF
        Dim barcodes = BarcodeReader.ReadPdf(result.FullPath)

        Dim output = String.Join(vbLf, barcodes.Select(Function(b) $"Page {b.PageNumber}: [{b.BarcodeType}] {b.Value}"))

        Await DisplayAlert("Scan Results", If(output.Length > 0, output, "No barcodes found."), "OK")
    End If
End Sub
$vbLabelText   $csharpLabel

輸出

.NET MAUI 條碼掃描器 SDK:在幾分鐘內建立跨平台掃描器:圖像 2 - 包含 QR 程式碼的 PDF 掃描輸出

方法 ReadPdf() 掃描 PDF 的所有頁面並返回條碼資料及頁碼,使其易於處理包含多個條碼的文件。 如果 PDF 跨越數十頁,考慮傳遞 BarcodeReaderOptions 物件,並將 PageNumbers 設置為特定範圍,以限制掃描到相關頁面並減少處理時間。

如何處理多個條碼和 QR 程式碼?

生產應用程式經常需要從單一圖像中檢測多個條碼或按條碼型別篩選結果。 類別 BarcodeReaderOptions 暴露了控制偵測行為的配置屬性。 將 ExpectMultipleBarcodes 設置為 true,告訴讀取器繼續掃描直至找到所有匹配項,而不是提前停止:

using IronBarCode;

// Configure the reader for multi-barcode detection with type filtering
var options = new BarcodeReaderOptions
{
    ExpectMultipleBarcodes = true,
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
    Speed = ReadingSpeed.Balanced
};

var barcodes = BarcodeReader.Read(imagePath, options);

foreach (var barcode in barcodes)
{
    Console.WriteLine($"Type: {barcode.BarcodeType}, Value: {barcode.Value}");
}
using IronBarCode;

// Configure the reader for multi-barcode detection with type filtering
var options = new BarcodeReaderOptions
{
    ExpectMultipleBarcodes = true,
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128,
    Speed = ReadingSpeed.Balanced
};

var barcodes = BarcodeReader.Read(imagePath, options);

foreach (var barcode in barcodes)
{
    Console.WriteLine($"Type: {barcode.BarcodeType}, Value: {barcode.Value}");
}
Imports IronBarCode

' Configure the reader for multi-barcode detection with type filtering
Dim options As New BarcodeReaderOptions With {
    .ExpectMultipleBarcodes = True,
    .ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128,
    .Speed = ReadingSpeed.Balanced
}

Dim barcodes = BarcodeReader.Read(imagePath, options)

For Each barcode In barcodes
    Console.WriteLine($"Type: {barcode.BarcodeType}, Value: {barcode.Value}")
Next
$vbLabelText   $csharpLabel

屬性 Speed 控制掃描時間和精確度之間的取捨。 ReadingSpeed.Faster 優先考量吞吐量,適合批量掃描高質量圖像的應用程式。ReadingSpeed.ExtraSlow 應用更多激進的圖像校正處理,用於面臨挑戰的輸入 - 低對比度、傾斜角度或部分被遮蔽的程式碼。 ReadingSpeed.Balanced 是大多數應用程式的合適起點。

枚舉 BarcodeEncoding 支持按位組合,因此您可以將掃描限制於與用例相關的符號學,而不因不必要的檢查而影響性能。

如何從記憶體流讀取條碼?

文件路徑在大多數情況下運作良好,但某些 .NET MAUI 工作流程通過記憶體傳遞圖像資料 — 從相機預覽中抓取的幀、從 REST API 下載的字節,或在進程中生成的圖像資料。 IronBarcode 支持直接在 BarcodeReader.Read() 超載上使用 System.IO.Stream 輸入:

using IronBarCode;
using System.IO;

// Read a barcode from a MemoryStream (e.g., an in-memory image buffer)
private BarcodeResult[] ReadFromStream(Stream imageStream)
{
    return BarcodeReader.Read(imageStream);
}

// Example: download an image and scan without writing to disk
private async Task<string> ScanDownloadedBarcode(string imageUrl)
{
    using var httpClient = new HttpClient();
    using var stream = await httpClient.GetStreamAsync(imageUrl);
    using var memoryStream = new MemoryStream();

    await stream.CopyToAsync(memoryStream);
    memoryStream.Position = 0;

    var barcodes = BarcodeReader.Read(memoryStream);
    return barcodes.Any() ? barcodes.First().Value : string.Empty;
}
using IronBarCode;
using System.IO;

// Read a barcode from a MemoryStream (e.g., an in-memory image buffer)
private BarcodeResult[] ReadFromStream(Stream imageStream)
{
    return BarcodeReader.Read(imageStream);
}

// Example: download an image and scan without writing to disk
private async Task<string> ScanDownloadedBarcode(string imageUrl)
{
    using var httpClient = new HttpClient();
    using var stream = await httpClient.GetStreamAsync(imageUrl);
    using var memoryStream = new MemoryStream();

    await stream.CopyToAsync(memoryStream);
    memoryStream.Position = 0;

    var barcodes = BarcodeReader.Read(memoryStream);
    return barcodes.Any() ? barcodes.First().Value : string.Empty;
}
Imports IronBarCode
Imports System.IO
Imports System.Net.Http
Imports System.Threading.Tasks

' Read a barcode from a MemoryStream (e.g., an in-memory image buffer)
Private Function ReadFromStream(imageStream As Stream) As BarcodeResult()
    Return BarcodeReader.Read(imageStream)
End Function

' Example: download an image and scan without writing to disk
Private Async Function ScanDownloadedBarcode(imageUrl As String) As Task(Of String)
    Using httpClient As New HttpClient()
        Using stream As Stream = Await httpClient.GetStreamAsync(imageUrl)
            Using memoryStream As New MemoryStream()
                Await stream.CopyToAsync(memoryStream)
                memoryStream.Position = 0

                Dim barcodes = BarcodeReader.Read(memoryStream)
                Return If(barcodes.Any(), barcodes.First().Value, String.Empty)
            End Using
        End Using
    End Using
End Function
$vbLabelText   $csharpLabel

流超載接受任何 Stream 子類,包括 FileStream 和網路流。 程式庫內部處理格式偵測,因此在呼叫 Read() 之前,您無需指定圖像型別。

如何在 MAUI 應用中生成條碼?

IronBarcode 處理條碼生成以及讀取。 類別 BarcodeWriter 產生條碼作為圖片文件、Bitmap 物件或可在 MAUI 視圖中顯示的 Stream 實例。 這對於需要列印或共享條碼的庫存應用程式非常有用,並且它可以與掃描功能並行使用:

using IronBarCode;

// Generate a QR code and display it in a MAUI Image control
private async void OnGenerateQrClicked(object sender, EventArgs e)
{
    // Create a QR code barcode
    var qrCode = QRCodeWriter.CreateQrCode(
        value: "https://ironsoftware.com/csharp/barcode/",
        qrCodeSize: 500,
        errorCorrection: QRCodeWriter.QrErrorCorrectionLevel.Medium
    );

    // Save to a temporary file and display
    var tempPath = Path.Combine(FileSystem.CacheDirectory, "generated-qr.png");
    qrCode.SaveAsPng(tempPath);

    GeneratedImageView.Source = ImageSource.FromFile(tempPath);
}
using IronBarCode;

// Generate a QR code and display it in a MAUI Image control
private async void OnGenerateQrClicked(object sender, EventArgs e)
{
    // Create a QR code barcode
    var qrCode = QRCodeWriter.CreateQrCode(
        value: "https://ironsoftware.com/csharp/barcode/",
        qrCodeSize: 500,
        errorCorrection: QRCodeWriter.QrErrorCorrectionLevel.Medium
    );

    // Save to a temporary file and display
    var tempPath = Path.Combine(FileSystem.CacheDirectory, "generated-qr.png");
    qrCode.SaveAsPng(tempPath);

    GeneratedImageView.Source = ImageSource.FromFile(tempPath);
}
Imports IronBarCode

' Generate a QR code and display it in a MAUI Image control
Private Async Sub OnGenerateQrClicked(sender As Object, e As EventArgs)
    ' Create a QR code barcode
    Dim qrCode = QRCodeWriter.CreateQrCode(
        value:="https://ironsoftware.com/csharp/barcode/",
        qrCodeSize:=500,
        errorCorrection:=QRCodeWriter.QrErrorCorrectionLevel.Medium
    )

    ' Save to a temporary file and display
    Dim tempPath = Path.Combine(FileSystem.CacheDirectory, "generated-qr.png")
    qrCode.SaveAsPng(tempPath)

    GeneratedImageView.Source = ImageSource.FromFile(tempPath)
End Sub
$vbLabelText   $csharpLabel

類別 QRCodeWriter 支持所有四個 QR 錯誤校正級別(低、中、四分位、高),自定義大小,和風格選項,包括前景/背景顏色控制。 對於非 QR 符號學,使用 BarcodeWriter.CreateBarcode() 並使用適當的 BarcodeEncoding 值。 條碼生成 API 參考文件所有支持的輸出格式。

本條碼掃描器程式庫的關鍵功能是什麼?

IronBarcode 為 .NET MAUI 條碼掃描項目提供了幾個優勢,這些優勢使其與 ZXing.Net.MAUI 等開源替代方案區分開來:

IronBarcode 用於 .NET MAUI 開發的功能
功能詳細資訊
跨平台支持從單一 NuGet 套件目標 Android、iOS 和 Windows
多個輸入來源從文件路徑、記憶體流和 PDF 文件掃描
格式覆蓋解碼 30 多個 1D 和 2D 符號學,包括 QR、Data Matrix 和 PDF417
條碼生成生成 QR 程式碼和 1D 條碼作為 PNG、點陣圖或流輸出
圖像校正自動處理旋轉、傾斜和低對比度的輸入
無本機 SDK 依賴純 .NET 程式庫,不需要平台特定的本機綁定

"無本機 SDK 依賴"這一點在 .NET MAUI 項目中至關重要,因為平台特定的本機程式庫需要為每個目標進行單獨的連結步驟。 IronBarcode 完全避開了這一複雜性意味著,無需額外配置,單一的 NuGet 參考便可為全部三個支持的平台生成工作中的二進制檔案。

欲知支持條碼格式的完整列表,請參閱 IronBarcode 支持格式文件。 有關生產部署的定價和授權條款,請查看 IronBarcode 授權頁

生產條碼掃描的最佳實踐是什麼?

將條碼掃描器部署到生產環境需要注意在基本讀取調用之外的幾個領域。 以下指南解決了 .NET MAUI 條碼應用程式中最常見的故障點。

選擇合適的讀取速度。 ReadingSpeed.Balanced 能正確處理大多數真實世界中的圖像。 對於列印文件或無法重拍的圖像保留 ReadingSpeed.ExtraSlow。 避開 ReadingSpeed.ExtraSlow 用於高容量工作流,因為每次掃描所需時間更長。

按預期型別篩選。 如果應用程式僅處理 QR 程式碼,請設置 ExpectBarcodeTypes = BarcodeEncoding.QRCode。 限制搜索範圍可減少處理時間,並消除背景圖形中存在的其他符號學的誤報。

僅在需要時使用 ExpectMultipleBarcodes 將其設置為 true 始終會導致讀取器進行額外的處理。 對於單一條碼輸入,保留預設值 (false),這樣掃描在找到首個有效程式碼後馬上返回。

優雅地處理空結果。 BarcodeReader.Read() 返回空陣列而不是在未檢測到任何條碼時拋出。 在存取 First() 之前檢查 .Any() 並向使用者展示清晰訊息。 一個帶有指導的重試提示("確保條碼光線充足且居中")比一般錯誤能更提高使用者體驗。

快取選項物件。 在每次掃描時建立 BarcodeReaderOptions 實例會增加分配。 在類別層級建構一次選項並跨呼叫重複使用。

請參閱 IronBarcode 故障排除指南條碼閱讀器教程 以獲得有關診斷掃描失敗和優化性能的附加支持。

您的下一步是什麼?

using IronBarcode 構建 .NET MAUI 條碼掃描器需要安裝單個 NuGet 套件、配置平台權限,並使用文件路徑或流調用 BarcodeReader.Read()。 相同的 API 無需平台特定的程式碼分支,即可目標 Android、iOS 和 Windows。

要進一步擴展應用程式,請考慮以下資源:

開始您的免費試用 以獲得開發授權金鑰,或者 探索生產部署的授權選項

常見問題

什麼是 .NET MAUI,為何條碼掃描整合具挑戰性?

.NET MAUI 是一個跨平台 UI 框架,從單一程式碼庫針對 Android、iOS 和 Windows。條碼掃描具有挑戰性,因為每個平台都曝光不同的相機和儲存 API。IronBarcode 提供了一個統一的 .NET API,為您處理平台差異。

IronBarcode 在 .NET MAUI 應用中支持哪些條碼格式?

IronBarcode 支持超過 30 種條碼型別,包括 QR Code,Code 128,Code 39,EAN-13,EAN-8,UPC-A,UPC-E,Data Matrix,PDF417,Aztec 和 ITF。使用 BarcodeEncoding 列舉來指定特定格式。

IronBarcode 可以在 .NET MAUI 應用中從 PDF 文件讀取條碼嗎?

可以。BarcodeReader.ReadPdf() 方法掃描 PDF 文件的所有頁面,並返回 BarcodeResult 集合。每個結果都包含條碼值、型別和頁碼。

IronBarcode 是否在所有的 .NET MAUI 目標平台上運作?

IronBarcode 支持在單個 NuGet 封裝內使用的 .NET MAUI 專案中的 Android、iOS 和 Windows 目標。不需要平台特定的本地 SDK 綁定。

如何從一張圖像中掃描多個條碼?

在 BarcodeReaderOptions 中設置 ExpectMultipleBarcodes = true,並將選項物件傳遞給 BarcodeReader.Read()。讀數器將進行額外掃描以檢測圖像中的所有條碼。

ReadingSpeed.Faster 和 ReadingSpeed.ExtraSlow 的區別是什麼?

ReadingSpeed.Faster 優先考量吞吐量,適合高品質圖像。而 ReadingSpeed.ExtraSlow 則應用更進取的圖像校正,適合挑戰性的輸入,如低對比度、旋轉或部分遮擋的條碼。

IronBarcode 能夠從 MemoryStream 中讀取條碼嗎?

可以。BarcodeReader.Read() 接受一個 System.IO.Stream 參數,其中包括 MemoryStream、FileStream 和網路流。這使得在不需寫入磁碟的情況下掃描記憶體圖像資料變得可能。

如何在 .NET MAUI 應用中使用 IronBarcode 生成 QR code?

using QRCodeWriter.CreateQrCode() 並設置目標值、大小和錯誤校正等級。使用 SaveAsPng() 將結果保存為 PNG 文件,並使用 ImageSource.FromFile() 在 MAUI Image 控件中顯示。

在 .NET MAUI Android 應用中進行條碼掃描需要哪些權限?

將 android.permission.READ_EXTERNAL_STORAGE 和 android.permission.CAMERA 新增到 AndroidManifest.xml 中。對於 iOS,加入 NSPhotoLibraryUsageDescription 和 NSCameraUsageDescription 鍵到 Info.plist。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話