public void encodeAndSaveWithEC(string text, string path, QR_CORRECT_LEV correctLev) { try { this.filePath = path; textToQRImage(text, (QR_CORRECT_LEV)correctLev).Save(path, ImageFormat.Bmp); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static public Bitmap textToQRImage(string text, QR_CORRECT_LEV correctLev) { try { if (writer == null) { writer = new QRCodeWriter(); } Hashtable hints = new Hashtable(); switch (correctLev) { case QR_CORRECT_LEV.L: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L; break; case QR_CORRECT_LEV.M: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.M; break; case QR_CORRECT_LEV.Q: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.Q; break; case QR_CORRECT_LEV.H: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H; break; default: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L; break; } ByteMatrix byteMatrix = writer.encode( text, BarcodeFormat.QR_CODE, size, size, hints); return(byteMatrix.ToBitmap()); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public static Bitmap textToQRImage(string text, QR_CORRECT_LEV correctLev) { try { if (writer == null) writer = new QRCodeWriter(); Hashtable hints = new Hashtable(); switch (correctLev) { case QR_CORRECT_LEV.L: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L; break; case QR_CORRECT_LEV.M: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.M; break; case QR_CORRECT_LEV.Q: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.Q; break; case QR_CORRECT_LEV.H: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H; break; default: hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L; break; } ByteMatrix byteMatrix = writer.encode( text, BarcodeFormat.QR_CODE, size, size, hints); return byteMatrix.ToBitmap(); } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } }