Skip to content

Commit 0d4984f

Browse files
committed
Added GetGraphicSmall to ASCIIQRCode.
Credits for qrcode-terminal.
1 parent cecf206 commit 0d4984f

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

QRCoder/ASCIIQRCode.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,51 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString
6262
}
6363
return qrCode.ToArray();
6464
}
65+
66+
/// <summary>
67+
/// Returns a strings that contains the resulting QR code as ASCII chars.
68+
/// </summary>
69+
/// <returns></returns>
70+
public string GetGraphicSmall()
71+
{
72+
string endOfLine = "\n";
73+
bool BLACK = true, WHITE = false;
74+
75+
var platte = new
76+
{
77+
WHITE_ALL = "\u2588",
78+
WHITE_BLACK = "\u2580",
79+
BLACK_WHITE = "\u2584",
80+
BLACK_ALL = " ",
81+
};
82+
83+
var moduleData = QrCodeData.ModuleMatrix;
84+
var lineBuilder = new StringBuilder();
85+
for (var row = 0; row < moduleData.Count; row += 2)
86+
{
87+
for (var col = 0; col < moduleData.Count; col++)
88+
{
89+
try
90+
{
91+
if (moduleData[col][row] == WHITE && moduleData[col][row + 1] == WHITE)
92+
lineBuilder.Append(platte.WHITE_ALL);
93+
else if (moduleData[col][row] == WHITE && moduleData[col][row + 1] == BLACK)
94+
lineBuilder.Append(platte.WHITE_BLACK);
95+
else if (moduleData[col][row] == BLACK && moduleData[col][row + 1] == WHITE)
96+
lineBuilder.Append(platte.BLACK_WHITE);
97+
else
98+
lineBuilder.Append(platte.BLACK_ALL);
99+
}
100+
catch (Exception)
101+
{
102+
lineBuilder.Append(platte.WHITE_BLACK);
103+
}
104+
105+
}
106+
lineBuilder.Append(endOfLine);
107+
}
108+
return lineBuilder.ToString();
109+
}
65110
}
66111

67112

0 commit comments

Comments
 (0)