private Bitmap GetQRCodeByZXingNet(String strMessage, Int32 width, Int32 height) { String imagePath = System.Windows.Forms.Application.StartupPath + "\\ICON.png"; Bitmap result = null; try { BarcodeWriter barCodeWriter = new BarcodeWriter(); barCodeWriter.Format = BarcodeFormat.QR_CODE; //barcode格式 barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); //編碼字元utf-8 barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); //錯誤校正等級 barCodeWriter.Options.Height = height; //高度 barCodeWriter.Options.Width = width; //寬度 barCodeWriter.Options.Margin = 0; //外邊距 ZXing.Common.BitMatrix bm = barCodeWriter.Encode(strMessage); //將訊息寫入 result = barCodeWriter.Write(bm); Bitmap overlay = new Bitmap(imagePath); //載入圖片 int deltaHeigth = result.Height - overlay.Height; //圖片y int deltaWidth = result.Width - overlay.Width; //圖片x Graphics g = Graphics.FromImage(result); //圖型 g.DrawImage(overlay, new Point(deltaWidth / 2, deltaHeigth / 2)); //畫出圖片 } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(result); }
public IActionResult Get() { var req = this.Request; switch (req.Host.Host) { case "localhost": case "127.0.0.1": return(Content("地址为127.0.0.1或localhost时,二维码不可用。")); } var obj = new { Name = name, Url = $"{req.Scheme}://{req.Host}", Password = password }; ZXing.Writer formatWriter = new ZXing.MultiFormatWriter(); ZXing.IBarcodeWriterSvg barcodeWriter = new ZXing.BarcodeWriterSvg(); ZXing.BarcodeFormat barcodeFormat = ZXing.BarcodeFormat.QR_CODE; Dictionary <ZXing.EncodeHintType, object> hints = new Dictionary <ZXing.EncodeHintType, object>() { [ZXing.EncodeHintType.CHARACTER_SET] = "UTF-8" }; ZXing.Common.BitMatrix bitMatrix = formatWriter.encode(JsonConvert.SerializeObject(obj), barcodeFormat, 400, 400, hints); var svgImage = barcodeWriter.Write(bitMatrix); var svgContent = svgImage.Content; return(this.Content(svgContent, "image/svg+xml", Encoding.UTF8)); }
/// <summary> /// 生成二维码 /// </summary> /// <returns></returns> public Bitmap creatQcode(string path) { try { int width = 232; //图片宽度 int height = 232; //图片长度 BarcodeWriter barCodeWriter = new BarcodeWriter(); barCodeWriter.Format = BarcodeFormat.QR_CODE; // 生成码的方式(这里设置的是二维码),有条形码\二维码\还有中间嵌入图片的二维码等 barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); // 支持中文字符串 barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); barCodeWriter.Options.Height = height; barCodeWriter.Options.Width = width; barCodeWriter.Options.Margin = 0; //设置的白边大小 ZXing.Common.BitMatrix bm = barCodeWriter.Encode(path); //DNS为要生成的二维码字符串 Bitmap result = barCodeWriter.Write(bm); Bitmap Qcbmp = result.Clone(new Rectangle(Point.Empty, result.Size), PixelFormat.Format1bppIndexed); //位深度 // SaveImg(currentPath, Qcbmp); //图片存储自己写的函数 //Qcbmp=WhiteUp(Qcbmp,10); return(Qcbmp); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(null); } }
/// <summary> /// 生成二维码 /// </summary> /// <param name="msg">二维码信息</param> /// <returns>图片</returns> private Bitmap GenByZXingNet(string msg) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); //编码问题 writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); const int codeSizeInPixels = 250; //设置图片长宽 writer.Options.Height = writer.Options.Width = codeSizeInPixels; writer.Options.Margin = 0;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(msg); Bitmap img = writer.Write(bm); //获取文本 string texts = this.textBox2.Text; //得到Bitmap(传入Rectangle.Empty自动计算宽高) Bitmap bmp = TextToBitmap(texts, this.textBox2.Font, Rectangle.Empty, this.textBox2.ForeColor, this.textBox2.BackColor); /*//上下合并 * int iWidth = bmp.Width > img.Width ? bmp.Width : img.Width; * int iHeight = bmp.Height + img.Height; * Bitmap bitmap = new Bitmap(iWidth, iHeight); * * Graphics g = Graphics.FromImage(bitmap); * g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel); * g.DrawImage(img, new Rectangle(0, bmp.Height, img.Width, img.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); * g.Dispose(); * * pictureBox1.Image = bitmap;*/ //上下合并 int iWidth = img.Width > bmp.Width ? img.Width : bmp.Width; int iHeight = img.Height + bmp.Height; Bitmap bitmap = new Bitmap(iWidth, iHeight); Graphics g = Graphics.FromImage(bitmap); g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); g.DrawImage(bmp, new Rectangle(0, img.Height, bmp.Width, bmp.Height), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel); g.Dispose(); pictureBox1.Image = bitmap; return(img); /* * //用PictureBox显示 * this.pictureBox2.Image = bmp; * * pictureBox1.Image = img; * */ }
private static Image GenerateQRCode(string Content) { ZXing.QrCode.QRCodeWriter qrc = new ZXing.QrCode.QRCodeWriter(); ZXing.Common.BitMatrix bmx = qrc.encode(Content, ZXing.BarcodeFormat.QR_CODE, 100, 100); ZXing.BarcodeWriter bcw = new ZXing.BarcodeWriter(); Bitmap bmp = bcw.Write(bmx); return((Image)bmp); }
/// <summary> /// 生成二维码 /// </summary> /// <param name="content">内容文本</param> /// <param name="size">图片尺寸(像素),0表示不设置</param> /// <param name="margin">二维码的边距,图片尺寸大于0生效</param> /// <param name="errorCorrection">纠错码等级</param> /// <param name="characterSet">内容编码</param> /// <returns></returns> public static System.Drawing.Image EncodeQrCode(string content, int size = 10, int margin = 2, string errorCorrection = "L", string characterSet = "utf-8") { BarcodeWriter barCodeWriter = new BarcodeWriter(); barCodeWriter.Format = BarcodeFormat.QR_CODE; QrCodeEncodingOptions options = new QrCodeEncodingOptions() { // DisableECI = true, CharacterSet = characterSet, // 设置内容编码 // QrVersion = 8, }; errorCorrection = errorCorrection.ToUpper(); IDictionary <string, int> dic = new Dictionary <string, int>() { { "L", 1 }, { "M", 0 }, { "Q", 3 }, { "H", 2 } }; if (!dic.ContainsKey(errorCorrection)) { errorCorrection = "L"; } if (size != 0) { int s; if (errorCorrection == "L" || errorCorrection == "M") { s = size * 27; } else { s = size * 31; } s += (margin - 1) * (size * 2); options.Width = s; options.Height = s; options.Margin = margin; // 设置二维码的边距,单位不是固定像素 } options.ErrorCorrection = ErrorCorrectionLevel.forBits(dic[errorCorrection]); barCodeWriter.Options = options; ZXing.Common.BitMatrix bm = barCodeWriter.Encode(content); Bitmap result = barCodeWriter.Write(bm); return(result); }
public static void ConvertByteQrCodeToWriteableBitmap(string content, string fileName, int width, string filePath) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Height = writer.Options.Width = width; writer.Options.Margin = 0;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(content); Bitmap bmap = writer.Write(bm); bmap.Save(filePath + @"\" + fileName, ImageFormat.Png); }
/// <summary> /// Code128 /// </summary> /// <param name="content"></param> /// <param name="fileName"></param> /// <param name="width"></param> /// <param name="filePath"></param> public static void GetCode128ToBitmap(string content, string fileName, int width, string filePath) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.CODE_128; writer.Options.Height = width / 4; writer.Options.Width = width; writer.Options.Margin = 0;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(content); Bitmap bmap = writer.Write(bm); bmap.Save(filePath + @"\" + fileName, ImageFormat.Png); }
public static Bitmap GenByZxingNet(string InputString, int WeightHeight) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); writer.Options.Height = writer.Options.Width = WeightHeight; writer.Options.Margin = 1; ZXing.Common.BitMatrix bm = writer.Encode(InputString); Bitmap img = writer.Write(bm); return(img); }
private void GenerateQrCode(string text) { QRCodeWriter qrWriter = new QRCodeWriter(); Dictionary <ZXing.EncodeHintType, object> hints = new Dictionary <ZXing.EncodeHintType, object>(); hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "windows-1251"); hints.Add(ZXing.EncodeHintType.MARGIN, 1); ZXing.Common.BitMatrix matrix = qrWriter.encode(text.Trim(), ZXing.BarcodeFormat.QR_CODE, 640, 640, hints); ZXing.Presentation.BarcodeWriter writer = new ZXing.Presentation.BarcodeWriter(); WriteableBitmap wb = writer.Write(matrix); this.image.Source = wb; }
/// <summary> /// 生成条码 /// /// </summary> /// <param name="content">加密内容,不能为空</param> /// <param name="w">宽</param> /// <param name="h">高</param> /// <returns></returns> public static Bitmap GenerateBarCode(String content, int w = 80, int h = 30) { if (string.IsNullOrEmpty(content)) { return(null); } Bitmap bitmap = null; BarcodeWriter barcodeWriter = new BarcodeWriter(); barcodeWriter.Format = BarcodeFormat.EAN_13; barcodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); barcodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); barcodeWriter.Options.Width = w; barcodeWriter.Options.Height = h; barcodeWriter.Options.Margin = 0; ZXing.Common.BitMatrix bitMatrix = barcodeWriter.Encode(content); bitmap = barcodeWriter.Write(bitMatrix); return(bitmap); }
/// <summary> /// 生成二维码 /// </summary> /// <param name="msg">二维码信息</param> /// <returns>图片</returns> private Bitmap GenByZXingNet(string msg) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题 writer.Options.Hints.Add( EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H ); const int codeSizeInPixels = 250; //设置图片长宽 writer.Options.Height = writer.Options.Width = codeSizeInPixels; writer.Options.Margin = 0;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(msg); Bitmap img = writer.Write(bm); return(img); }
/// <summary> /// 生成条码图片 /// </summary> /// <param name="strMessage">要生成二维码的字符串</param> /// <param name="width">二维码图片宽度</param> /// <param name="height">二维码图片高度</param> /// <returns></returns> private Bitmap GetBarCodeByZXingNet(String strMessage, Int32 width, Int32 height) { Bitmap result = null; try { BarcodeWriter barCodeWriter = new BarcodeWriter(); barCodeWriter.Format = BarcodeFormat.CODE_128; barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); barCodeWriter.Options.Height = height; barCodeWriter.Options.Width = width; barCodeWriter.Options.Margin = 0; ZXing.Common.BitMatrix bm = barCodeWriter.Encode(strMessage); result = barCodeWriter.Write(bm); } catch { throw; } return(result); }
/// <summary> /// 生成二维码图片 /// </summary> /// <param name="strMessage">要生成二维码的字符串</param> /// <param name="width">二维码图片宽度</param> /// <param name="height">二维码图片高度</param> /// <returns></returns> private Bitmap GetQRCodeByZXingNet(String strMessage, Int32 width, Int32 height) { Bitmap result = null; try { BarcodeWriter barCodeWriter = new BarcodeWriter(); barCodeWriter.Format = BarcodeFormat.QR_CODE; barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8"); barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); barCodeWriter.Options.Height = height; barCodeWriter.Options.Width = width; barCodeWriter.Options.Margin = 0; ZXing.Common.BitMatrix bm = barCodeWriter.Encode(strMessage); result = barCodeWriter.Write(bm); } catch (Exception ex) { //异常输出 } return(result); }
/// <summary> /// 把文本转换成Bitmap /// </summary> /// <param name="content">文本内容</param> /// <param name="size">图片大小</param> /// <param name="barcodeFormat">条码种类</param> /// <param name="margin">外边距</param> /// <param name="encoding">编码模式</param> /// <param name="errorCorrectionLevel">错误修正等级</param> /// <returns></returns> public static Bitmap TextToBitmap( string content, Size size, BarcodeFormat barcodeFormat, int margin = 0, string encoding = "UTF-8", ErrorCorrectionLevel errorCorrectionLevel = null) { try { //在生成图片之前先处理下Size然后在下方加上数据 BarcodeWriter barcodeWriter = new BarcodeWriter(); barcodeWriter.Format = barcodeFormat; barcodeWriter.Options.Width = size.Width; barcodeWriter.Options.Height = size.Height; barcodeWriter.Options.Margin = margin; barcodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, encoding); barcodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel ?? ErrorCorrectionLevel.H); ///bit矩阵?? ZXing.Common.BitMatrix bitMatrix = barcodeWriter.Encode(content); Bitmap bitmap = barcodeWriter.Write(bitMatrix); RectangleF rectangleF = new RectangleF() { X = 0, Y = bitmap.Size.Height, Width = bitmap.Size.Width, Height = (bitmap.Size.Height / 10), }; bitmap = (Bitmap)QRCodeCommon.QRCodeAddContent(bitmap, content, rectangleF); if (bitmap == null) { throw new Exception("生成二维码失败"); } else { return(bitmap); } } catch (Exception) { throw; } }
public void CreateQRCode(HSSFWorkbook wb, ISheet sheet, string value, int rownum, int colnum) { //todo 计算二维码的大小和位置 int sheetmergecount = sheet.NumMergedRegions; rownum = rownum - 1; colnum = colnum - 1; for (int k = sheetmergecount - 1; k >= 0; k--) { CellRangeAddress ca = sheet.GetMergedRegion(k); if ((rownum >= ca.FirstRow) && (rownum <= ca.LastRow) && (colnum >= ca.FirstColumn) && (colnum <= ca.LastColumn)) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题 writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); writer.Options.Height = writer.Options.Width = 256; writer.Options.Margin = 1;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(value); Bitmap img = writer.Write(bm); byte[] buffer = BitmapToBytes(img); if (buffer == null) { break; } HSSFClientAnchor anchor; anchor = new HSSFClientAnchor(0, 0, 0, 0, ca.FirstColumn, ca.FirstRow, ca.LastColumn + 1, ca.LastRow + 1); anchor.AnchorType = (AnchorType)2; HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); int pictureIndex = wb.AddPicture(buffer, PictureType.JPEG); HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIndex); break; } else { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题 writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); writer.Options.Height = writer.Options.Width = 256; writer.Options.Margin = 1;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(value); Bitmap img = writer.Write(bm); byte[] buffer = BitmapToBytes(img); if (buffer == null) { break; } HSSFClientAnchor anchor; anchor = new HSSFClientAnchor(0, 0, 0, 0, colnum, rownum, colnum + 1, rownum + 1); anchor.AnchorType = (AnchorType)2; HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); int pictureIndex = wb.AddPicture(buffer, PictureType.JPEG); HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIndex); break; } } if (sheetmergecount == 0) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; writer.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");//编码问题 writer.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H); writer.Options.Height = writer.Options.Width = 256; writer.Options.Margin = 1;//设置边框 ZXing.Common.BitMatrix bm = writer.Encode(value); Bitmap img = writer.Write(bm); byte[] buffer = BitmapToBytes(img); if (buffer == null) { return; } HSSFClientAnchor anchor; anchor = new HSSFClientAnchor(0, 0, 0, 0, colnum, rownum, colnum + 1, rownum + 1); anchor.AnchorType = (AnchorType)2; HSSFPatriarch patriarch = (HSSFPatriarch)sheet.CreateDrawingPatriarch(); int pictureIndex = wb.AddPicture(buffer, PictureType.JPEG); HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIndex); } }
public JObject QrCodeGenerator() { JObject jobj; string baseString = ""; string conf_code = ""; string overlayImagePath = System.Web.HttpContext.Current.Server.MapPath("/images/") + ConfigurationManager.AppSettings["QrCodeOverlayImage"].ToString(); conf_code = "grpTalk" + System.Guid.NewGuid().ToString(); conf_code = conf_code.Replace("-", "").Replace(" ", ""); //GENERATE_QR_CODE("12345678910111213456789987456321456987456321"); ZXing.Common.BitMatrix bitmatrix = default(ZXing.Common.BitMatrix); Bitmap bmp_image = default(Bitmap); string qr_to_str = null; IBarcodeWriter writer = default(IBarcodeWriter); try { writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.QrCode.QrCodeEncodingOptions { Margin = 0, Width = 500, Height = 500, ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L } }; qr_to_str = conf_code;//CryptoUtil.Encrypt(conf_code); bitmatrix = writer.Encode(qr_to_str); bmp_image = new Bitmap(bitmatrix.Width, bitmatrix.Height); for (int i = 0; i <= bmp_image.Height - 1; i++) { for (int j = 0; j <= bmp_image.Width - 1; j++) { if (bitmatrix[i, j]) { bmp_image.SetPixel(i, j, Color.Black); } else { bmp_image.SetPixel(i, j, Color.White); } } } Bitmap overlay = new Bitmap(overlayImagePath); int deltaHeigth = bmp_image.Height - overlay.Height; int deltaWidth = bmp_image.Width - overlay.Width; Graphics g = Graphics.FromImage(bmp_image); g.DrawImage(overlay, new Point(deltaWidth / 2, deltaHeigth / 2)); MemoryStream stream = new MemoryStream(); bmp_image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); byte[] imageBytes = stream.ToArray(); baseString = Convert.ToBase64String(imageBytes); jobj = new JObject( new JProperty("Success", true), new JProperty("Message", "Success"), new JProperty("ConfCode", conf_code), new JProperty("BaseString", baseString)); } catch (Exception ex) { HttpContext.Current.Response.Write(ex.ToString()); jobj = new JObject(new JProperty("Success", false), new JProperty("Message", "Something Went Wrong")); } Pusher pusherObj = new Pusher("99686", "ed522d982044e2680be6", "2d2388bc3972643d5b5b"); ITriggerResult PusherResponse = null; PusherResponse = pusherObj.Trigger(conf_code, "client-myEvent", new { AccessToken = "outbound" }); Logger.TraceLog("pusher response :" + PusherResponse.ToString()); return(jobj); }
public Bitmap serializePattern() { MemoryStream ms = new MemoryStream(); BinaryWriter br = new BinaryWriter(ms); br.Write(padBytes(0)); byte[] nameBytes = UnicodeEncoding.Unicode.GetBytes(designName); int pad = 41 - nameBytes.Length; br.Write(nameBytes); if (pad > 0) br.Write(padBytes(pad)); // These are *1 and 2, the first two bytes of the unique id. br.Write(padBytes(2)); byte[] creatorBytes = UnicodeEncoding.Unicode.GetBytes(creatorName); pad = 20 - nameBytes.Length; br.Write(creatorBytes); if (pad > 0) br.Write(padBytes(pad)); // Special bytes 3 and 4. br.Write(padBytes(2)); byte[] cityBytes = UnicodeEncoding.Unicode.GetBytes(cityName); pad = 18 - nameBytes.Length; br.Write(cityBytes); if (pad > 0) br.Write(padBytes(pad)); br.Write(padBytes(4)); for (int i = 0; i < 15; i++) { br.Write(new byte[]{NewLeafBitmap.findPalIndexInv(this.design.filepal[i])}); } // Special byte 7. br.Write(padBytes(1)); br.Write(new byte[] { (byte)0x0A }); br.Write(new byte[] { (byte)0x09 }); br.Write(padBytes(2)); BitArray halfBytes = new BitArray(1024*4); int counter = 0; List<byte> blist = new List<byte>(); for (int i = 0; i < 32; i++) for (int j = 0; j < 32; j++) { blist.Add((byte)(this.design.falseColor.GetPixel(j,i).ToArgb())); } int counterR = 0; for (int i = 0; i < blist.Count; ) { BitArray halfWord = new BitArray(new byte[] { blist[i] }); halfBytes[counterR + 4] = halfWord[0]; halfBytes[counterR + 5]= halfWord[1]; halfBytes[counterR + 6] = halfWord[2]; halfBytes[counterR + 7] = halfWord[3]; halfWord = new BitArray(new byte[] { blist[i + 1] }); halfBytes[counterR + 0] = halfWord[0]; halfBytes[counterR + 1] = halfWord[1]; halfBytes[counterR + 2] = halfWord[2]; halfBytes[counterR + 3] = halfWord[3]; counterR += 8; i += 2; } FileStream fs = File.Open("C:/DATASETS/serialize.txt", FileMode.Create); // ms.CopyTo(fs); byte[] junk = copyOctetwiseReverse(ms.ToArray()); BitArray a = new BitArray(junk); // a = a.Append(new BitArray(4)); BitArray ab = a.Append(halfBytes); BitArray header = new BitArray(new byte[]{QR_MAGIC}); header.Reverse(); BitArray header2 = new BitArray(new byte[] { 38 }); header2.Reverse(); BitArray header3 = new BitArray(4); header3.Set(1, true); header3.Set(1, true); header3.Set(0, true); header3.Set(0, true); //header = header2.Prepend(header); BitArray all = header.Append(header2); all = all.Append(header3); all = all.Append(ab); byte[] omni = all.ToByteArray(); MessageBox.Show(BitConverter.ToString(omni)); fs.Write(omni,0,omni.Length); // fs.WriteByte(0xEC); // fs.WriteByte(0x11); // fs.WriteByte(0xEC); // fs.WriteByte(0x11); System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1"); QRCodeWriter qrw = new QRCodeWriter(); // for (int i = 0; i < omni.Length; i++) // { // omni[i] = (byte)((sbyte)omni[i]); // } Dictionary<EncodeHintType, object> h = new Dictionary<EncodeHintType, object>(); h.Add(ZXing.EncodeHintType.CHARACTER_SET, "CP437"); h.Add(ZXing.EncodeHintType.DISABLE_ECI, true); h.Add(ZXing.EncodeHintType.ERROR_CORRECTION,ZXing.QrCode.Internal.ErrorCorrectionLevel.H); ZXing.QrCode.QrCodeEncodingOptions qrec = new QrCodeEncodingOptions(); var writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new QrCodeEncodingOptions { Height = 188, Width = 188, CharacterSet = "CP437", PureBarcode = true, ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L, DisableECI = false, } }; char[] chars = new char[omni.Length]; for (int i = 0; i < omni.Length; i++) { chars[i] = (char) omni[i]; } ZXing.Common.BitMatrix bmx = writer. Encode(Encoding.GetEncoding("CP437").GetString(omni));//qrw.encode(new String(), ZXing.BarcodeFormat.QR_CODE, 300, 300); //bmx = createBinQRCode(omni, omni.Length, 0); fs.Close(); ms.Close(); //return bmx.ToBitmap(); ZXing.BarcodeWriter ss= new ZXing.BarcodeWriter(); ZXing.IBarcodeWriter reader = new BarcodeWriter(); ZXing.Rendering.BitmapRenderer bmpr = new ZXing.Rendering.BitmapRenderer(); MessageBox.Show(Encoding.GetEncoding("CP437").GetString(omni).Substring(0, 10)); return bmpr.Render(bmx, writer.Format, Encoding.GetEncoding("CP437").GetString(omni)); // Gma.QrCodeNet.Encoding.QrEncoder hi = new Gma.QrCodeNet.Encoding.QrEncoder(); // Gma.QrCodeNet.Encoding.QrCode qr = new Gma.QrCodeNet.Encoding.QrCode(); // // hi.ErrorCorrectionLevel = Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L; // hi.TryEncode(omni, out qr); // SVGRenderer svg = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), new FormColor(Color.Black), new FormColor(Color.White)); // FileStream FSX = new FileStream("C:/DATASETS/QR.svg", FileMode.Create); //svg.WriteToStream(qr.Matrix, FSX); // FSX.Close(); // Bitmap bmp2 = new Bitmap(qr.Matrix.Width, qr.Matrix.Height); // for (int i = 0; i < qr.Matrix.Width; i++) // for (int j = 0; j < qr.Matrix.Height; j++) // bmp2.SetPixel(i, j, qr.Matrix.InternalArray[i, j] ? Color.Black : Color.White); // bmp2.Save("C:/DATASETS/gma"); // return bmp2; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Start); lista = LDbConnection.GetActualUserExpo(); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetDisplayShowTitleEnabled(false); SupportActionBar.SetHomeButtonEnabled(true); SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); drawerLayout = FindViewById <Android.Support.V4.Widget.DrawerLayout>(Resource.Id.drawer_layout); navigationView = FindViewById <Android.Support.Design.Widget.NavigationView>(Resource.Id.nav_view); navigationView.NavigationItemSelected += HomeNavigationView_NavigationItemSelected; var qrcode = FindViewById <Android.Widget.ImageView>(Resource.Id.Start_qrcode); var writer = new ZXing.QrCode.QRCodeWriter(); String s = ""; if (LDbConnection.getUserType() == "Uczestnik") { s = "Uczestnik:" + LDbConnection.GetUser().Email; } else if (LDbConnection.getUserType() == "Wystawca") { s = "Wystawca:" + LDbConnection.GetCompany().Email; } ZXing.Common.BitMatrix bm = writer.encode(s, ZXing.BarcodeFormat.QR_CODE, 500, 500); Android.Graphics.Bitmap ImageBitmap = Android.Graphics.Bitmap.CreateBitmap(500, 500, Config.Argb8888); for (int i = 0; i < 500; i++) { //width for (int j = 0; j < 500; j++) { //height ImageBitmap.SetPixel(i, j, bm[i, j] ? Color.Black : Color.White); } } if (ImageBitmap != null) { qrcode.SetImageBitmap(ImageBitmap); } var expo_list = FindViewById <Android.Widget.Spinner>(Resource.Id.Start_targi); expo_list.ItemSelected += new System.EventHandler <Android.Widget.AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected); var adapter = new MyExpoSingleListViewAdapter(lista, this); expo_list.Adapter = adapter; var btn1 = (Button)FindViewById(Resource.Id.Start_join); btn1.Visibility = Android.Views.ViewStates.Invisible; btn1.Click += delegate { var NxtAct = new Android.Content.Intent(this, typeof(UserActivity)); StartActivity(NxtAct); }; var button = FindViewById <Android.Widget.Button>(Resource.Id.Start_scan); button.Click += async delegate { ZXing.Mobile.MobileBarcodeScanner scanner; ZXing.Mobile.MobileBarcodeScanner.Initialize(Application); scanner = new ZXing.Mobile.MobileBarcodeScanner(); scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.BottomText = "Poczekaj, aż kod kreskowy będzie automatycznie zeskanowany!"; //Start scanning var result = await scanner.Scan(); scanner.Cancel(); if (result == null) { scanner.Cancel(); } else { scanner.Cancel(); string[] scan = result.Text.Split(':'); if (scan[0] == "Wystawca") { var NxtAct = new Android.Content.Intent(this, typeof(CompanyActivity)); NxtAct.PutExtra("Email", scan[1]); NxtAct.PutExtra("expo_id", lista[select].Id); NxtAct.PutExtra("Search", result.Text); NxtAct.PutExtra("Show", true); StartActivity(NxtAct); } else if (scan[0].Contains("Uczestnik")) { System.Console.WriteLine("Uczestnik"); var NxtAct = new Android.Content.Intent(this, typeof(UserActivity)); NxtAct.PutExtra("Email", scan[1]); NxtAct.PutExtra("expo_id", lista[select].Id); NxtAct.PutExtra("Search", result.Text); NxtAct.PutExtra("Show", true); StartActivity(NxtAct); } } }; if (lista == null) { button.Visibility = Android.Views.ViewStates.Invisible; btn1.Visibility = Android.Views.ViewStates.Visible; } }
private async Task GetQrCodeAsync(Update update, Employee employee) { string receiverCode = employee.Place.Id.ToString() + "-" + employee.Id.ToString(); string qrString = "ST00011|Name=ООО Чаевые-24|PersonalAcc=40702810970010113722|BankName=МОСКОВСКИЙ ФИЛИАЛ АО КБ \"МОДУЛЬБАНК\"|" + "BIC=044525092|CorrespAcc=30101810645250000092|PayeeINN=1651083591|" + "Purpose=Дарение чаевых коллективу по договору-оферте tips24.ru/" + receiverCode + "|" + "PayerAddress=" + employee.Place.City + ", " + employee.Place.Address + "|LastName=Гость|FirstName=заведения"; //string qrString = "ST00011|Name=ИП Галяутдинов Ринат Ибрагимович|PersonalAcc=40802810470210002677|BankName=МОСКОВСКИЙ ФИЛИАЛ АО КБ \"МОДУЛЬБАНК\"|BIC=044525092|CorrespAcc=30101810645250000092|PayeeINN=165117672519|" + // "Purpose=Дарение чаевых коллективу по договору-оферте tips24.ru/" + receiverCode + "|" + // "PayerAddress="+ employee.PlaceCity + ", " + employee.PlaceAddress + "|LastName=Гость|FirstName=заведения"; byte[] hash = GetQrHash(qrString); if (employee.QrCode != null && employee.QrCode.IsValid(hash)) { ReplyKeyboardMarkup keyboard = GetStandardKeyboardMarkup(employee); Message response = await _telegramClient.SendPhotoAsync(update.Message.From.Id, new InputOnlineFile(employee.QrCode.FileId), null, ParseMode.Default, false, 0, keyboard, _cts.Token); await this.WriteMessageLog(new QrCodeOutputMessageLog(employee, employee.QrCode.FileId, receiverCode, keyboard)); return; } QRCodeWriter qrWriter = new QRCodeWriter(); Dictionary <ZXing.EncodeHintType, object> hints = new Dictionary <ZXing.EncodeHintType, object>(); hints.Add(ZXing.EncodeHintType.CHARACTER_SET, "windows-1251"); hints.Add(ZXing.EncodeHintType.MARGIN, 1); ZXing.Common.BitMatrix matrix = qrWriter.encode(qrString, ZXing.BarcodeFormat.QR_CODE, 640, 640, hints); BarcodeWriter <Rgb24> writer = new BarcodeWriter <Rgb24>(); string fileId = null; using (MemoryStream ms = new MemoryStream()) { using (Image <Rgb24> image = writer.Write(matrix)) { image.Save(ms, new PngEncoder() { ColorType = PngColorType.Grayscale, BitDepth = PngBitDepth.Bit8 }); } ms.Position = 0; ReplyKeyboardMarkup keyboard = GetStandardKeyboardMarkup(employee); Message response = await _telegramClient.SendPhotoAsync(update.Message.From.Id, new InputOnlineFile(ms), null, ParseMode.Default, false, 0, keyboard, _cts.Token); fileId = response.Photo[0].FileId; await this.WriteMessageLog(new QrCodeOutputMessageLog(employee, fileId, receiverCode, keyboard)); } using (SqlConnection conn = _sqlServer.GetConnection()) { await conn.OpenAsync(); using (SqlCommand cmd = _sqlServer.GetSpCommand("telegram.UpdateQrCodeFileId", conn)) { cmd.AddBigIntParam("@UserId", employee.TelegramUserId); cmd.AddVarCharParam("@QrCodeFileId", 64, fileId); cmd.AddBinaryParam("@QrCodeStringHash", 40, hash); await cmd.ExecuteNonQueryAsync(); } } }