Created
February 18, 2014 09:18
-
-
Save podhmo/9067403 to your computer and use it in GitHub Desktop.
qr encode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using ZXing; | |
using ZXing.Common; | |
using ZXing.QrCode; | |
using ZXing.QrCode.Internal; | |
namespace ConsoleApplication7 | |
{ | |
class Program | |
{ | |
public static void Toplevel(string qrValue) | |
{ | |
var W = 48; | |
var H = 48; | |
var height = H; | |
var width = W; | |
var margin = 0; | |
var barcodeWriter = new BarcodeWriter | |
{ | |
Format = BarcodeFormat.QR_CODE, | |
Options = new EncodingOptions | |
{ | |
Height = height, | |
Width = width, | |
Margin = margin | |
} | |
}; | |
using (var bitmap = barcodeWriter.Write(qrValue)) | |
{ | |
Console.WriteLine(bitmap); | |
Console.WriteLine("Width: {0}", bitmap.Width); | |
Console.WriteLine("Height: {0}", bitmap.Height); | |
Console.WriteLine("Size: {0}", bitmap.Size); | |
Console.WriteLine("HResolution: {0}", bitmap.HorizontalResolution); | |
Console.WriteLine("VResolution: {0}", bitmap.VerticalResolution); | |
//bitmap.Save("foo.bmp"); | |
} | |
} | |
static void LowLevel(string qrValue) | |
{ | |
//QRCode | |
var writer = new QRCodeWriter(); | |
var hints = new Dictionary<EncodeHintType, object>(); | |
var qrCode = ZXing.QrCode.Internal.Encoder.encode("hohoho", ErrorCorrectionLevel.H, hints); | |
var bitMatrix = qrCode.Matrix; | |
//Console.WriteLine(qrCode.Matrix); | |
//var bitMatrix = writer.encode(qrValue, BarcodeFormat.QR_CODE, W, H); | |
for (var y = 0; y < bitMatrix.Height; y++) | |
{ | |
for (var x = 0; x < bitMatrix.Width; x++) | |
{ | |
Console.Write("{0}", bitMatrix[x, y] == 1 ? "x" : "_"); | |
} | |
Console.WriteLine(""); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var qrValue = "whatever data you want to put in here"; | |
Toplevel(qrValue); | |
LowLevel(qrValue); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment