static void LogException(Exception exception) { try { string data = exception.Message + ";;" + exception.TargetSite + ";;" + exception.StackTrace; ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter(); writer.Format = ZXing.BarcodeFormat.QR_CODE; ZXing.Common.BitMatrix matrix = writer.Encode(data); int scale = 2; Bitmap result = new Bitmap(matrix.Width * scale, matrix.Height * scale); for (int x = 0; x < matrix.Height; x++) for (int y = 0; y < matrix.Width; y++) { Color pixel = matrix[x, y] ? Color.Black : Color.White; for (int i = 0; i < scale; i++) for (int j = 0; j < scale; j++) result.SetPixel(x * scale + i, y * scale + j, pixel); } result.Save(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\crash-" + DateTime.Now.Ticks + ".png"); } catch (Exception) { // FML. } }
private Image CreateQRCode(AC.Pattern pattern, int scale) { ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter(); writer.Format = ZXing.BarcodeFormat.QR_CODE; string data = new string(pattern.GetRawData().Select(b => Convert.ToChar(b)).ToArray()); ZXing.Common.BitMatrix matrix = writer.Encode(data); Bitmap result = new Bitmap(matrix.Width * scale, matrix.Height * scale); // This is probably better done with LockBits. Meh. for (int x = 0; x < matrix.Height; x++) for (int y = 0; y < matrix.Width; y++) { Color pixel = matrix[x, y] ? Color.Black : Color.White; for (int i = 0; i < scale; i++) for (int j = 0; j < scale; j++) result.SetPixel(x * scale + i, y * scale + j, pixel); } return result; }