Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Intermittent problem reading QR codes

Aperta
#601 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
cli

Direzione di ricerca

The failure is in decoding screen-captured QR codes, so the relevant code is the ZXing.Net decoder path for QR detection and binarization, not the writer shown in the report. Reproduce by decoding the saved screenshot (d:\QrReceive.Source.*.png) with BarcodeReader and TryHarder enabled, then compare against the generated PixelData bitmap. Done would mean a reproducible failing sample and a fix that keeps existing QR tests passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I’m looking for some advice on reading QR codes I created via ZXing.net. Ideally, I’d like to use QR codes with higher data density. But as the density goes up, so does the failure rate.

My workflow is to create a QR code, then display it on screen to confirm it’s what I need. The displayed code is not scaled or otherwise distorted.

All QR codes appear to be created correctly, and I can scan them using my shaky handheld phone, which is pointed at the monitor.

However, occasionally ZXing refuses to scan some QR codes, like the example below.

Changing the Margin and PureBarcode will change the size of the image, but the system still has problems reading some codes, at a rate of about 1 per 30.

I'm using v0.16.10 net48 from NuGet

Here is my code that creates the QR code:

            [int]$Size = 500
           
            $BarcodeWriter  = [ZXing.BarcodeWriterPixelData]::New()
            $BarcodeWriter.Format           = [ZXing.BarcodeFormat]::QR_CODE
            $BarcodeWriter.Options          = [ZXing.Common.EncodingOptions]::New()
            $BarcodeWriter.Options.Width    = $Size
            $BarcodeWriter.Options.Height   = $Size
            # $BarcodeWriter.Options.Margin   = 4
            # $BarcodeWriter.Options.NoPadding = $True
            # $BarcodeWriter.Options.PureBarcode = $True
 
            $PixelData = $BarcodeWriter.Write( $Text )
 
            $Bitmap     = [System.Drawing.Bitmap]::New( $PixelData.Width, $PixelData.Height, [System.Drawing.Imaging.PixelFormat]::Format32bppRgb )
            $BitmapData     = $Bitmap.LockBits(
                [System.Drawing.rectangle]::New( 0,0, $PixelData.Width, $PixelData.Height )
                , [System.Drawing.Imaging.ImageLockMode]::WriteOnly
                , $Bitmap.PixelFormat
                ) # end LockBits
            [System.Runtime.InteropServices.Marshal]::Copy( $PixelData.Pixels, 0, $BitmapData.Scan0, $PixelData.Pixels.Length )
            $Bitmap.UnlockBits( $BitmapData )
 
     Return $Bitmap

This is my code that collects a screenshot of the exact location where a QR code is being displayed, and the call to ZXing

            $bitmap = New-Object System.Drawing.Bitmap( $Area.Width, $Area.Height )
            $graphics = [System.Drawing.Graphics]::FromImage( $bitmap )
            $graphics.CopyFromScreen( $Area.Location, [System.Drawing.Point]::Empty, $Area.Size )
            $bitmap.Save( "d:\QrReceive.Source.$( $Guid ).png", [System.Drawing.Imaging.ImageFormat]::Png )

            $BarCodeReader = [ZXing.BarcodeReader]::New()
            $BarCodeReader.Options.TryHarder = $True
            $PossibleFormats = New-Object System.Collections.Generic.List[ZXing.BarcodeFormat]
            $PossibleFormats.Add( [ZXing.BarcodeFormat]::QR_Code )
            $BarCodeReader.Options.PossibleFormats = $PossibleFormats
            # $BarCodeReader.Options.PureBarcode = $True

            $Barcode = $BarCodeReader.Decode( $bitmap )

Here is that screenshot collected by the above code.

Image

Lingua principale
C#
Stelle
3.1k
Fork
704
Merge medio
13g 17h
PR unite (30g)
2

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di micjahn/ZXing.Net

Tutte le issue di micjahn/ZXing.Net

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.