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
13 changes: 7 additions & 6 deletions QRCoder/ASCIIQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@

namespace QRCoder
{
public class AsciiQRCode : AbstractQRCode<string>, IDisposable
public class AsciiQRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public AsciiQRCode() { }

public AsciiQRCode(QRCodeData data) : base(data) { }

/// <summary>
/// Returns a strings that contains the resulting QR code as ASCII chars.
/// </summary>
/// <param name="repeatPerModule">Number of repeated darkColorString/whiteSpaceString per module.</param>
/// <returns></returns>
public override string GetGraphic(int repeatPerModule)
public string GetGraphic(int repeatPerModule)
{
return string.Join("\n", GetLineByLineGraphic(repeatPerModule));
}
Expand Down Expand Up @@ -86,9 +91,5 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString
}
return qrCode.ToArray();
}
public void Dispose()
{
this.QrCodeData = null;
}
}
}
20 changes: 17 additions & 3 deletions QRCoder/AbstractQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
namespace QRCoder
{
public abstract class AbstractQRCode<T>
public abstract class AbstractQRCode
{
protected QRCodeData QrCodeData { get; set; }

protected AbstractQRCode() {
}

protected AbstractQRCode(QRCodeData data) {
this.QrCodeData = data;
}

public abstract T GetGraphic(int pixelsPerModule);

/// <summary>
/// Set a QRCodeData object that will be used to generate QR code. Used in COM Objects connections
/// </summary>
/// <param name="data">Need a QRCodeData object generated by QRCodeGenerator.CreateQrCode()</param>
virtual public void SetQRCodeData(QRCodeData data) {
this.QrCodeData = data;
}

public void Dispose()
{
this.QrCodeData = null;
}
}
}
15 changes: 13 additions & 2 deletions QRCoder/Base64QRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@

namespace QRCoder
{
public class Base64QRCode : AbstractQRCode<string>, IDisposable
public class Base64QRCode : AbstractQRCode, IDisposable
{
private QRCode qr;

/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public Base64QRCode() {
qr = new QRCode();
}

public Base64QRCode(QRCodeData data) : base(data) {
qr = new QRCode(data);
}

public override void SetQRCodeData(QRCodeData data) {
this.qr.SetQRCodeData(data);
}

public override string GetGraphic(int pixelsPerModule)
public string GetGraphic(int pixelsPerModule)
{
return this.GetGraphic(pixelsPerModule, Color.Black, Color.White, true);
}
Expand Down
14 changes: 7 additions & 7 deletions QRCoder/BitmapByteQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ namespace QRCoder
{

// ReSharper disable once InconsistentNaming
public class BitmapByteQRCode : AbstractQRCode<byte[]>, IDisposable
public class BitmapByteQRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public BitmapByteQRCode() { }

public BitmapByteQRCode(QRCodeData data) : base(data) { }

public override byte[] GetGraphic(int pixelsPerModule)
public byte[] GetGraphic(int pixelsPerModule)
{
return GetGraphic(pixelsPerModule, new byte[] { 0x00, 0x00, 0x00 }, new byte[] { 0xFF, 0xFF, 0xFF });
}
Expand Down Expand Up @@ -91,10 +96,5 @@ private byte[] IntTo4Byte(int inp)
}
return bytes;
}

public void Dispose()
{
this.QrCodeData = null;
}
}
}
14 changes: 7 additions & 7 deletions QRCoder/PngByteQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace QRCoder
{
public sealed class PngByteQRCode : AbstractQRCode<byte[]>, IDisposable
public sealed class PngByteQRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public PngByteQRCode() { }

public PngByteQRCode(QRCodeData data) : base(data)
{
}

public void Dispose()
{
this.QrCodeData?.Dispose();
this.QrCodeData = null;
}

/// <summary>
/// Creates a black &amp; white PNG of the QR code, using 1-bit grayscale.
/// </summary>
public override byte[] GetGraphic(int pixelsPerModule)
public byte[] GetGraphic(int pixelsPerModule)
{
using (var png = new PngBuilder())
{
Expand Down
2 changes: 1 addition & 1 deletion QRCoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
[assembly: ComVisible(true)]

// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("e668b98b-83bb-4e60-b33c-4fd5ed9c0156")]
Expand Down
14 changes: 7 additions & 7 deletions QRCoder/QRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ namespace QRCoder
{
using System;

public class QRCode : AbstractQRCode<Bitmap>, IDisposable
public class QRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public QRCode() { }

public QRCode(QRCodeData data) : base(data) {}

public override Bitmap GetGraphic(int pixelsPerModule)
public Bitmap GetGraphic(int pixelsPerModule)
{
return this.GetGraphic(pixelsPerModule, Color.Black, Color.White, true);
}
Expand Down Expand Up @@ -130,10 +135,5 @@ internal GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadi
roundedRect.CloseFigure();
return roundedRect;
}

public void Dispose()
{
this.QrCodeData = null;
}
}
}
16 changes: 7 additions & 9 deletions QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace QRCoder
{
public class SvgQRCode : AbstractQRCode<string>, IDisposable
public class SvgQRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public SvgQRCode() { }
public SvgQRCode(QRCodeData data) : base(data) { }


public override string GetGraphic(int pixelsPerModule)

public string GetGraphic(int pixelsPerModule)
{
var viewBox = new Size(pixelsPerModule*this.QrCodeData.ModuleMatrix.Count, pixelsPerModule * this.QrCodeData.ModuleMatrix.Count);
return this.GetGraphic(viewBox, Color.Black, Color.White);
Expand Down Expand Up @@ -71,10 +74,5 @@ private string CleanSvgVal(double input)
//Clean double values for international use/formats
return input.ToString(System.Globalization.CultureInfo.InvariantCulture);
}

public void Dispose()
{
this.QrCodeData = null;
}
}
}
10 changes: 7 additions & 3 deletions QRCoder/UnityQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

namespace QRCoder
{
public class UnityQRCode : AbstractQRCode<Texture2D>
public class UnityQRCode : AbstractQRCode
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public UnityQRCode() { }
public UnityQRCode(QRCodeData data) : base(data) {}

public override Texture2D GetGraphic(int pixelsPerModule)
public Texture2D GetGraphic(int pixelsPerModule)
{
return this.GetGraphic(pixelsPerModule, Color.black, Color.white);
}
Expand Down
14 changes: 7 additions & 7 deletions QRCoder/XamlQRCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

namespace QRCoder
{
public class XamlQRCode : AbstractQRCode<DrawingImage>, IDisposable
public class XamlQRCode : AbstractQRCode, IDisposable
{
/// <summary>
/// Constructor without params to be used in COM Objects connections
/// </summary>
public XamlQRCode() { }

public XamlQRCode(QRCodeData data) : base(data) { }

public override DrawingImage GetGraphic(int pixelsPerModule)
public DrawingImage GetGraphic(int pixelsPerModule)
{
return this.GetGraphic(pixelsPerModule, true);
}
Expand Down Expand Up @@ -61,10 +66,5 @@ public DrawingImage GetGraphic(Size viewBox, Brush darkBrush, Brush lightBrush,

return new DrawingImage(drawing);
}

public void Dispose()
{
this.QrCodeData = null;
}
}
}