Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions QRCoder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRCoderSamples", "QRCoderSamples\QRCoderSamples.csproj", "{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -183,6 +185,22 @@ Global
{F046136A-7BEA-49F3-9415-70CE50AD533B}.Release|x64.Build.0 = Release|Any CPU
{F046136A-7BEA-49F3-9415-70CE50AD533B}.Release|x86.ActiveCfg = Release|Any CPU
{F046136A-7BEA-49F3-9415-70CE50AD533B}.Release|x86.Build.0 = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|ARM.ActiveCfg = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|ARM.Build.0 = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|x64.ActiveCfg = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|x64.Build.0 = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|x86.ActiveCfg = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Debug|x86.Build.0 = Debug|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|Any CPU.Build.0 = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|ARM.ActiveCfg = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|ARM.Build.0 = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x64.ActiveCfg = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x64.Build.0 = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x86.ActiveCfg = Release|Any CPU
{61ED615B-C22C-5E3E-DAAD-A77A820E16DF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions QRCoderSamples/QRCoderSamples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<NoWarn>$(NoWarn);CA1707</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\QRCoder\QRCoder.csproj" />
</ItemGroup>

</Project>
84 changes: 84 additions & 0 deletions QRCoderSamples/ReadmeSamples.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using QRCoder;

namespace QRCoderSamples;

/// <summary>
/// Sample code from the README.md file
/// </summary>
public static class ReadmeSamples
{
/// <summary>
/// Quick Start - Generate a simple black and white PNG QR code
/// </summary>
public static void QuickStart_SimplePng()
{
// Generate a simple black and white PNG QR code
byte[] qrCodeImage = PngByteQRCodeHelper.GetQRCode("Hello World", QRCodeGenerator.ECCLevel.Q, 20);
}

/// <summary>
/// Quick Start - Generate a scalable black and white SVG QR code
/// </summary>
public static void QuickStart_SimpleSvg()
{
// Generate a scalable black and white SVG QR code
using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q);
using var svgRenderer = new SvgQRCode(qrCodeData);
string svg = svgRenderer.GetGraphic();
}

/// <summary>
/// Payload Generator - Create a bookmark payload
/// </summary>
public static void PayloadGenerator_Bookmark()
{
// Create a bookmark payload
var bookmarkPayload = new PayloadGenerator.Bookmark("https://github.com/Shane32/QRCoder", "QRCoder Repository");

// Generate the QR code data from the payload
using var qrCodeData = QRCodeGenerator.GenerateQrCode(bookmarkPayload);

// Or override the ECC level
using var qrCodeData2 = QRCodeGenerator.GenerateQrCode(bookmarkPayload, QRCodeGenerator.ECCLevel.H);

// Render the QR code
using var pngRenderer = new PngByteQRCode(qrCodeData);
byte[] qrCodeImage = pngRenderer.GetGraphic(20);
}

/// <summary>
/// Micro QR Code - Generate a Micro QR code
/// </summary>
public static void MicroQRCode_Simple()
{
// Generate a Micro QR code (versions M1-M4, represented as -1 to -4)
using var qrCodeData = QRCodeGenerator.GenerateMicroQrCode("Hello", QRCodeGenerator.ECCLevel.L, requestedVersion: -2);
using var qrCode = new PngByteQRCode(qrCodeData);
byte[] qrCodeImage = qrCode.GetGraphic(20);
}

/// <summary>
/// Working with QRCodeData - Access the module matrix directly
/// </summary>
public static void QRCodeData_ModuleMatrix()
{
// Generate QR code data
using var qrCodeData = QRCodeGenerator.GenerateQrCode("Hello World", QRCodeGenerator.ECCLevel.Q);

// Access the module matrix
var moduleMatrix = qrCodeData.ModuleMatrix;
int size = moduleMatrix.Count; // Size of the QR code (includes quiet zone)

// Manually render as ASCII (versus the included ASCII renderer)
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; x++)
{
// Check if module is dark (true) or light (false)
bool isDark = moduleMatrix[y][x];
Console.Write(isDark ? "██" : " ");
}
Console.WriteLine();
}
}
}
Loading