ZXingCpp.Angle 1.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ZXingCpp.Angle --version 1.0.0
                    
NuGet\Install-Package ZXingCpp.Angle -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZXingCpp.Angle" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZXingCpp.Angle" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ZXingCpp.Angle" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZXingCpp.Angle --version 1.0.0
                    
#r "nuget: ZXingCpp.Angle, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZXingCpp.Angle@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZXingCpp.Angle&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ZXingCpp.Angle&version=1.0.0
                    
Install as a Cake Tool

ZXingCpp.Angle

非官方修改版:基于 zxing-cpp 3.1.1 与官方 .NET 封装 ZXingCpp 0.5.3,新增一维条码任意角度识别。

⚠️ 这是替代包:请用它替换官方的 ZXingCpp 包,不要把两个包同时引用(托管程序集同名)。

相对上游的改进

项目 上游 3.1.1 本包
一维码可读角度 0°/90°(倾斜约 8~19° 以上就失败,取决于条码宽高比) ±45° + 0°/90°
细模组条码(1~2 px/模块、无抗锯齿截图) 常常失败 亚像素(2 点/像素)采样后可读
小条码在大照片里(占画面 2% 左右) 常失败 瓦片候选区域 + 细角度扫描后可读
反向读取时的识别框 可能被拉成对角线 已修正

解码结果(内容、格式、Position、Rotation)语义与官方一致;rotation() 折叠在 (-90°, 90°] (例如同一条轴会报 -64° 而不是 118°,两者等价)。

用法(核心 API)

与官方一致。注意用 ZXingCpp.ImageFormat 全限定,避免和 System.Drawing.Imaging.ImageFormat 歧义:

using System.Drawing;
using System.Drawing.Imaging;
using ZXingCpp;

using var bmp = new Bitmap(path);
var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                        ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
var iv = new ImageView(data.Scan0, bmp.Width, bmp.Height, ZXingCpp.ImageFormat.BGRA, data.Stride);
var reader = new BarcodeReader { TryHarder = true, TryRotate = true, TryInvert = true };
foreach (var bc in reader.From(iv))
    Console.WriteLine($"{bc.Format} {bc.Text} rot={bc.Orientation}°");   // 0~359 官方方向角

Barcode.Orientation 是 0~359 的方向角;Barcode.Rotation 是本包把它折叠到 (-90°, 90°] 的便捷值(同一条轴会报 -64° 而不是 118°,两者等价)。

注意:把图片画到新的 32bpp 位图上时用 DrawImage(src, 0, 0, src.Width, src.Height)(显式宽高), 否则 GDI+ 会按 DPI 缩放,条码被缩小后可能解不出。

增强托管 API(与 demo 一致)

本包内置了 demo 程序使用的一站式封装(using ZXingAngleDemo;),读整图、直接拿结果:

using System.Drawing;
using ZXingCpp;
using ZXingAngleDemo;   // BarcodeScanner / ScanResult / BarcodeInfo

using var bmp = new Bitmap(path);
using var opts = BarcodeScanner.MakeOptions(tryHarder: true, tryRotate: true, tryInvert: true,
                                            tryDownscale: true, formatPreset: "全部", minLineCount: 2, maxSymbols: 0);
var r = BarcodeScanner.Scan(bmp, opts);
foreach (var b in r.Barcodes)
    Console.WriteLine($"{b.Format} \"{b.Text}\" rot={b.Rotation}° lines={b.LineCount} pts={b.Points.Length}");

BarcodeScanner 还提供 MakeOptions、PresetFormats、Rotate(Bitmap, angle, color)、Ensure32bpp。

平台

本包托管层面向 net8.0-windows,原生库只带 win-x64 (runtimes/win-x64/native/ZXing.dll)。其它平台请自行用修改后的源码编译 (-DBUILD_SHARED_LIBS=ON -DZXING_C_API=ON)。

许可与声明

Apache-2.0,见随包的 LICENSE。对上游源码的修改清单见 NOTICE.md(Apache-2.0 §4(b) 要求声明修改)。 本项目与 zxing-cpp 作者无关,也未获其背书;问题请提到本包仓库,不要打扰上游。

Product Compatible and additional computed target framework versions.
.NET net8.0-windows is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.1-angle.2 40 10/17/2026
3.1.1-angle.1 40 10/17/2026
1.0.0 39 10/18/2026

1.0.0 正式版:托管层内置增强 API(BarcodeScanner/ScanResult/BarcodeInfo、Barcode.Rotation/Orientation/LineCount/Points、ImageView 支持 IntPtr 与 ReadOnlySpan),目标框架 net8.0-windows;基于 zxing-cpp 3.1.1 新增一维条码任意角度识别(±45°)、亚像素采样、瓦片搜索、反向读取位置修正。取代预发布版 3.1.1-angle.x。