Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created August 5, 2022 12:17
Show Gist options
  • Save brianmed/19418b1f7c69adf1f31fec1a7dda1055 to your computer and use it in GitHub Desktop.
Save brianmed/19418b1f7c69adf1f31fec1a7dda1055 to your computer and use it in GitHub Desktop.
ZXing QRcode with ImageSharp and without System.Drawing
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using ZXing;
using ZXing.Common;
/*
<ItemGroup>
<PackageReference Include="ZXing.Net.Bindings.ImageSharp.V2" Version="0.16.14" />
</ItemGroup>
*/
namespace CommandLineEncoder
{
class Program
{
static void Main(string[] args)
{
int width = 250; // width of the Qr Code
int height = 250; // height of the Qr Code
int margin = 0;
BarcodeWriterPixelData qrCodeWriter = new ZXing.BarcodeWriterPixelData
{
Format = ZXing.BarcodeFormat.QR_CODE,
Options = new EncodingOptions()
{
Height = height,
Width = width,
Margin = margin
}
};
ZXing.Rendering.PixelData pixelData = qrCodeWriter.Write(args[0]);
using (Image<Rgba32> img = Image.LoadPixelData<Rgba32>(pixelData.Pixels, width, height))
{
img.SaveAsPng("joy.png");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment