开源项目QRCoder介绍

简介

QRCoder是一个简单的库,用C#.NET编写,可让您创建QR码。

它与其他库没有任何依赖关系,并且可以在NuGet上以.NET Framework和.NET Core PCL版本获得。

有关更多信息,请参见:QRCode Wiki | 创作者的博客(英语)| 创作者的博客(德语)

QRCoder是Raffael Herrmann的项目,于10/2013首次发布。 它已获得MIT许可。

 

安装

签出此Github存储库,或通过NuGet软件包管理器安装QRCoder。 如果要使用NuGet,只需搜索“ QRCoder”或在NuGet软件包管理器控制台中运行以下命令:

PM>安装包QRCoder
注意:NuGet提要仅包含稳定版本。 如果您不需要最新的版本,则将以下网址之一添加到Visual Studio的NuGet包管理器选项的“包源”中。

NuGet V3提要URL(Visual Studio 2015+):https://www.myget.org/F/qrcoder/api/v3/index.json

NuGet V2提要URL(Visual Studio 2012+):https://www.myget.org/F/qrcoder/api/v2

 

使用

您只需要五行代码即可生成和查看您的第一个QR码。

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

 

可选参数和重载

GetGraphics方法具有更多的重载。 前两个使您可以设置QR码图形的颜色。 一种使用Color-class-types,另一种使用HTML十六进制颜色表示法。

//Set color by using Color-class types
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkRed, Color.PaleGreen, true);

//Set color by using HTML hex color notation
Bitmap qrCodeImage = qrCode.GetGraphic(20, "#000ff0", "#0ff000");

另一个重载使您可以在QR码的中心渲染徽标/图像。

Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile("C:\\myimage.png"));

还有很多其他选择。 因此,随时可以在我们的Wiki上阅读更多内容:Wiki:如何使用QRCoder

 

项目地址:https://github.com/codebude/QRCoder/

posted @ 2020-03-28 20:49  古道轻风  阅读(2497)  评论(1编辑  收藏  举报