IRONSOFTWAREHOME
Escáner de Códigos QR con 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
Escáner de Códigos QR con Blazor

Escáner de Códigos QR con Blazor

Use IronQR para escanear códigos QR en una aplicación de servidor Blazor. Sube una imagen a través del navegador con el componente InputFile de Blazor, luego decódala del lado del servidor con QrReader.Read().

Guía de 5 pasos para escanear un código QR en 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);

Explicación del código

InputFile.OnChange se activa cuando el usuario selecciona un archivo. OpenReadStream transmite la carga del navegador a una ruta temporal del servidor, que luego se pasa a AnyBitmap.FromFile para decodificar el formato de la imagen. Un QrImageInput envuelve el mapa de bits para IronQR, y QrReader.Read devuelve un IEnumerable<QrResult>. FirstOrDefault recupera de manera segura el primer resultado sin lanzar una excepción en imágenes que no contienen código QR.

Descubra cómo construir un escáner de código QR Blazor con IronQR.

¿Listo para empezar?

Nuget Downloads 74,386Versión:2026.9recién lanzado

Key in blue circle

Obtenga su clave de prueba gratuita de 30 días al instante.

Your trial license will be sent to your email address

Sin limitaciones. 100 % desbloqueado. Sin tarjeta de crédito.

bullet_checkedNo se requiere tarjeta de crédito ni creación de cuentaSin limitaciones. 100 % desbloqueado. Sin tarjeta de crédito.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Reserve su Demostración en Vivo gratuita
Booking Badge

Confiado por millones de ingenieros en todo el mundo

Logos de clientes de Iron Software
Obtén tu Consulta Sin Compromiso
Completa el formulario a continuación o envía un correo a sales@ironsoftware.com
Tus detalles siempre serán mantenidos confidenciales.
Confiado por millones de ingenieros en todo el mundo
Logos de clientes de Iron Software
Obtenga su Clave de Prueba de 30 días gratis al instante.
No se requiere tarjeta de crédito ni creación de cuenta