public void DecodeImageTest() { QRCodeEncoder encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; encoder.QRCodeVersion = 4; string content = "Hello World"; var cellWidth = 6; var img = new QRImage(encoder).EncodeImage(content, cellWidth); Assert.IsNotNull(img, "Image is not null"); QRCodeDecoder decoder = new QRCodeDecoder(); QRCodeBitmapImage bitmapImg = new QRCodeBitmapImage(img); var result = decoder.decode(bitmapImg); Assert.AreEqual(content, result); }
public void EncodeImageTest() { QRCodeEncoder encoder = new QRCodeEncoder(); encoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; encoder.QRCodeVersion = 4; string content = "Hello World"; var cellWidth = 6; var img = new QRImage(encoder).EncodeImage(content, cellWidth); Assert.IsNotNull(img, "Image is not null"); var halfCellWidth = cellWidth / 2; var cells = encoder.EncodeData(content); for (int i = 0; i < cells.Length; i++) { for (int j = 0; j < cells.Length; j++) { // Add offset for middle of cell. var x = (i * cellWidth) + halfCellWidth; var y = (j * cellWidth) + halfCellWidth; var pixColor = img.GetPixel(x, y); var expected = cells[i][j] ? Color.Black : Color.White; Assert.AreEqual(expected.R, pixColor.R); Assert.AreEqual(expected.G, pixColor.G); Assert.AreEqual(expected.B, pixColor.B); } } img.Save("HelloWorld" + new Random().Next(100, 999) + "_QR.bmp"); }