codebude/QRCoder

Why not use Color struct instead of byte[] in color parameters?

Closed this issue · 1 comments

Type of issue

[ ] Bug
[x] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

In the GetGraphic method from the QRCoder.PngByteQRCode class, the darkColorRgba and the lightColorRgba use byte[] to represent RGBA color. I expected to use Color struct. It's much easier.

// QRCoder.PngByteQRCode
public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgba, byte[] lightColorRgba, bool drawQuietZones = true)
{
	using (PngBuilder pngBuilder = new PngBuilder())
	{
		int num = (base.QrCodeData.ModuleMatrix.Count - ((!drawQuietZones) ? 8 : 0)) * pixelsPerModule;
		pngBuilder.WriteHeader(num, num, 1, PngBuilder.ColorType.Indexed);
		pngBuilder.WritePalette(darkColorRgba, lightColorRgba);
		pngBuilder.WriteScanlines(DrawScanlines(pixelsPerModule, drawQuietZones));
		pngBuilder.WriteEnd();
		return pngBuilder.GetBytes();
	}
}

Current Behavior

The byte[] is not convenient on the usage.

Possible Solution (optional)

Provide pleomorphism that accept Color struct.

Your Environment

  • Version used: 1.4.3
  • Compiled from source or NuGet package?: NuGet
  • Payload/Encoded text: 123
  • Used payload generator: N/A
  • Used ECC-level: Q
  • Used renderer class: Default
  • Environment (.NET 3.5, .NET 4.X, .NETCore, ...): .NET 7

I decided to pass colors as byte[] to keep the PngByteQRCode free from any Windows dependencies. By adding System.Drawing just for the Color-class we had a dependency that isn't available on all platforms/in all environments. This would add another layer of complexity - in the codebase as also on the documentation side.

You can see in the compatibility matrix, that PngByteQRCode is one of the few renderers that works on all platforms and I really want to keep this feature:
https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers#2-overview-of-the-different-renderers