DEV Community

Bawan
Bawan

Posted on

Decoding QR codes on the desktop: what's inside a small open-source Windows scanner

Phones read QR codes so well that we forget it's a separate problem when the code is already on your monitor: a 2FA enrollment page, a screenshot in a chat, a code inside a PDF or a design mockup. The usual workaround is to point the phone at your own screen. I wanted to see how a desktop tool handles this, so I looked at Qr Code Scanner for PC, a Windows app published under Apache 2.0. It's a fork of barcodrod.io by Mark Hopper, so most of what follows applies to the original project too.

The stack

The app is built on WinUI 3 and the Windows App SDK, running on .NET 9. Decoding is done by ZXing.Net, the .NET port of the well-known Java ZXing library. Camera input goes through AForge.NET's DirectShow layer. The solution is split into two projects, the UI application and a separate Core project for shared logic, with an installer project and CI workflows next to them. Nothing exotic, which is a good thing: every piece is a mature, documented library.

One decoder, many inputs

The interesting design point is that every input source ends up as the same thing: a bitmap handed to ZXing. Only how the bitmap is obtained changes.

Screen: instead of writing its own capture overlay, the app relies on the Windows Snipping Tool. The user selects a region, the result arrives as an image, and it gets decoded. Reusing the OS tool avoids a whole class of problems around multiple monitors, DPI scaling and overlay windows.

Files and clipboard: an image is loaded or pasted and passed straight to the decoder.

Webcam: frames come in through DirectShow, which is why virtual devices such as OBS Virtual Camera also work. Anything that registers as a DirectShow video source can feed the scanner.

Folder: the same decode call runs in a loop over image files, which is useful for batch jobs such as checking a stack of generated labels.

Symbologies

ZXing gives you 17 formats for free: 2D codes (QR, Data Matrix, PDF417, Aztec) and the common 1D ones (Code 128, EAN, UPC and others). If you've ever had to verify barcodes coming out of a label printer or a ticketing system, being able to decode them from a screenshot without special hardware saves real time.

Generation

The reverse direction uses the same library. The app has templates for Wi-Fi credentials, contacts and email, which are just well-known payload formats inside a QR code: the Wi-Fi one, for example, is a string with SSID, auth type and password fields that phone cameras know how to parse. You can also pick colors and the error-correction level. Higher correction makes the code denser but lets it survive damage or a logo placed in the middle.

Privacy decisions

Three choices here are worth copying in any tool that handles QR codes. All decoding is local, and the app works offline with no telemetry. Decoded URLs are shown to the user before anything opens, which matters because a QR code is an unreadable link, and auto-opening it is exactly what "quishing" (QR phishing) relies on. Scan history can be exported or switched off entirely, since decoded payloads often contain Wi-Fi passwords or one-time secrets.

Limitations

It's Windows-only (10 and 11, x64), and the screen mode depends on the Snipping Tool being available. The download is a fairly large zip, around 74 MB, mostly because of the bundled Windows App SDK and .NET runtime rather than the app's own code.

Takeaway

If you're building something similar, the architecture is a useful pattern: normalize every input into a bitmap, keep one decoding path, reuse OS facilities for capture instead of reinventing them, and treat decoded content as untrusted input. The code is small enough to read in an evening.

Top comments (0)

The discussion has been locked. New comments can't be added.