IRONSOFTWAREHOME
Scanner de QR Code Blazor
using IronQr;
using IronSoftware.Drawing;

private string? qrImageSrc;
private string scannedText = string.Empty;

private async Task OnFileSelected(InputFileChangeEventArgs e)
{
    var file = e.File;
    var tempPath = Path.Combine(Path.GetTempPath(), file.Name);
    await using var stream = file.OpenReadStream(maxAllowedSize: 10_000_000);
    await using var fs = File.Create(tempPath);
    await stream.CopyToAsync(fs);
    qrImageSrc = tempPath;
}

private async Task ScanQRCode()
{
    // Load the scanned QR code
    var inputBmp = AnyBitmap.FromFile(qrImageSrc!);
    var imageInput = new QrImageInput(inputBmp);
    var reader = new QrReader();

    // Read the scanned QR code
    var results = reader.Read(imageInput);

    // Check if a result was found
    var firstResult = results.FirstOrDefault();
    if (firstResult != null)
    {
        // Save the QR code value as a string
        scannedText = firstResult.Value;
    }
    else
    {
        scannedText = "No QR code found in the selected image.";
    }
}
Imports IronQr
Imports IronSoftware.Drawing

Private qrImageSrc As String
Private scannedText As String = String.Empty

Private Async Function OnFileSelected(e As InputFileChangeEventArgs) As Task
    Dim file = e.File
    Dim tempPath = Path.Combine(Path.GetTempPath(), file.Name)
    Await Using stream = file.OpenReadStream(maxAllowedSize:=10000000)
        Await Using fs = File.Create(tempPath)
            Await stream.CopyToAsync(fs)
        End Using
    End Using
    qrImageSrc = tempPath
End Function

Private Async Function ScanQRCode() As Task
    ' Load the scanned QR code
    Dim inputBmp = AnyBitmap.FromFile(qrImageSrc)
    Dim imageInput = New QrImageInput(inputBmp)
    Dim reader = New QrReader()

    ' Read the scanned QR code
    Dim results = reader.Read(imageInput)

    ' Check if a result was found
    Dim firstResult = results.FirstOrDefault()
    If firstResult IsNot Nothing Then
        ' Save the QR code value as a string
        scannedText = firstResult.Value
    Else
        scannedText = "No QR code found in the selected image."
    End If
End Function
NuGet Download
PM > Install-Package IronQR
Scanner de QR Code Blazor

Scanner de QR Code Blazor

Utilisez IronQR pour scanner les codes QR dans une application Blazor Server. Téléchargez une image via le navigateur avec le composant InputFile de Blazor, puis décodez-la côté serveur avec QrReader.Read().

Guide en 5 étapes pour scanner un code QR dans Blazor

  • using IronQr;
  • using IronSoftware.Drawing;
  • await using var stream = file.OpenReadStream(maxAllowedSize: 10_000_000);
  • var inputBmp = AnyBitmap.FromFile(qrImageSrc!);
  • var results = reader.Read(imageInput);

Explication du code

InputFile.OnChange se déclenche lorsque l'utilisateur sélectionne un fichier. OpenReadStream transmet le téléchargement du navigateur vers un chemin serveur temporaire, qui est ensuite passé à AnyBitmap.FromFile pour décoder le format de l'image. Un QrImageInput encapsule le bitmap pour IronQR, et QrReader.Read retourne un IEnumerable<QrResult>. FirstOrDefault récupère en toute sécurité le premier résultat sans jeter d'exception sur les images qui ne contiennent pas de code QR.

Découvrez comment construire un scanner de codes QR Blazor avec IronQR.

Prêt à commencer?

Nuget Downloads 74,386Version :2026.9vient de sortir

Key in blue circle

Obtenez votre clé d'essai de 30 jours instantanément.

Your trial license will be sent to your email address

Aucune restriction. 100 % débloqué. Pas de carte bancaire.

bullet_checkedAucune carte de crédit ou création de compte requiseAucune restriction. 100 % débloqué. Pas de carte bancaire.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Réservez votre Démonstration en direct gratuite
Booking Badge

De confiance par des millions d'ingénieurs dans le monde entier

Logos des clients d'Iron Software
Obtenez Votre Consultation sans Engagement
Remplissez le formulaire ci-dessous ou envoyez un email à sales@ironsoftware.com
Vos informations seront toujours gardées confidentielles.
De confiance par des millions d'ingénieurs dans le monde entier
Logos des clients d'Iron Software
Obtenez votre clé d'essai 30 jours gratuitement.
Aucune carte de crédit ou création de compte requise