private void renderQRCode() { string level = comboBox1.SelectedItem.ToString(); QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(textBoxQRCode.Text, eccLevel); pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20, Color.Black, Color.White, getIconBitmap()); }
public Form2() { InitializeComponent(); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode("https://play.google.com/store/apps/details?id=eu.dirtyharry.opsiadmin", QRCodeGenerator.ECCLevel.Q); appbox.BackgroundImage = qrCode.GetGraphic(2); }
private string SaveQrCodeImage(EquipmentInfo equipmentInfo) { var qrcodeUrl = _host + "/EquipmentInfo/ViewInWeChat?id=" + equipmentInfo.Id; var qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrcodeUrl, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(100); var fileName = $"{equipmentInfo.Id}.png"; var fullfileName = Path.Combine(QrCodeStorageRoot, fileName); qrCodeImage.Save(fullfileName, ImageFormat.Png); return(QrCodeVirtualPath.Replace("~", "") + fileName); }
private static byte[] GetQrBytes(string qrContent) { var qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrContent, QRCoder.QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(30); using (MemoryStream stream = new MemoryStream()) { qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png); return(stream.ToArray()); } }
void genQrcode4btc() { //=======生成BTC钱包二维码=======// string strCode = lb4btc0addr.Text; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Teal, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); qr4btc.Image = qrCodeImage; }
/// <summary> /// 生成二维码 /// </summary> /// <param name="msg">信息</param> /// <param name="version">版本 1 ~ 40</param> /// <param name="pixel">像素点大小</param> /// <param name="icon_path">图标路径</param> /// <param name="icon_size">图标尺寸</param> /// <param name="icon_border">图标边框厚度</param> /// <param name="white_edge">二维码白边</param> /// <returns>位图</returns> public static Bitmap QRCode(string msg, int version, int pixel, string icon_path, int icon_size, int icon_border, bool white_edge) { QRCoder.QRCodeGenerator code_generator = new QRCoder.QRCodeGenerator(); QRCoder.QRCodeData code_data = code_generator.CreateQrCode(msg, QRCoder.QRCodeGenerator.ECCLevel.M /* 这里设置容错率的一个级别 */, true, true, QRCoder.QRCodeGenerator.EciMode.Utf8, version); QRCoder.QRCode code = new QRCoder.QRCode(code_data); Bitmap icon = new Bitmap(icon_path); Bitmap bmp = code.GetGraphic(pixel, Color.Black, Color.White, icon, icon_size, icon_border, white_edge); return(bmp); }
public string CreateQR(string text) { QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.M); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); //MemoryStream ms = new MemoryStream(); //qrCodeImage.Save(ms, ImageFormat.Jpeg); qrCodeImage.Save($"{AppDomain.CurrentDomain.BaseDirectory}{RF.BarCodeName}.jpg"); return($"{AppDomain.CurrentDomain.BaseDirectory}{RF.BarCodeName}.jpg"); // 如果想保存图片 可使用 qrCodeImage.Save(filePath); }
/// <summary> /// 构造QrCode /// </summary> /// <param name="content"></param> /// <returns></returns> public static byte[] BuildQrCode(string content) { QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); using (Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false)) { using (MemoryStream ms = new MemoryStream()) { qrCodeImage.Save(ms, ImageFormat.Jpeg); return(ms.ToArray()); } } }
/// <summary> /// 获取二维码 Bitmap /// </summary> /// <returns></returns> public Bitmap GetBitmap() { // 生成二维码的内容 QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(this.plainText, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(this.Size, this.Foreground, this.Background, this.icon, this.iconSize, 1, false); if (!this.QrIsBorder) { return(qrCodeImage); } return(WhiteBorder(qrCodeImage, this.QrCodeBorderWidth, this.QrCodeBorderColor)); }
public ActionResult InviteQRCode() { string url = Request.Url.Scheme + "://" + Request.Url.Host + "/User/Register/" + User.Identity.Name; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); return(File(ms.ToArray(), @"image/jpeg")); }
public static byte[] Generate(int pixelsPerModule, string strCode) { byte[] result = null; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.M); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(pixelsPerModule, Color.Black, Color.White, null, 15, 6, false); using (MemoryStream ms = new MemoryStream()) { qrCodeImage.Save(ms, ImageFormat.Jpeg); result = ms.ToArray(); } return(result); }
private Byte[] CreateQrCode(string v) { QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(v, QRCoder.QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); //convert Bitmap to ByteArray in MemoryStream (https://stackoverflow.com/questions/7350679/convert-a-bitmap-into-a-byte-array) using (var stream = new MemoryStream()) { qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png); Byte[] byteBild = stream.ToArray(); return(byteBild); } //ImageConverter converter = new ImageConverter(); //https://stackoverflow.com/questions/7350679/convert-a-bitmap-into-a-byte-array }
public string CreateQR(string uniqueText) { string qrCodeImageAsBase64 = string.Empty; try { QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(uniqueText, QRCoder.QRCodeGenerator.ECCLevel.Q); Base64QRCode qrCode = new Base64QRCode(qrCodeData); qrCodeImageAsBase64 = qrCode.GetGraphic(10, Color.DarkBlue, Color.DarkGray, (Bitmap)Bitmap.FromFile(@"C:\myIco.png")); } catch (Exception ex) { Console.WriteLine($"Exception Details:{ex.Message}"); } return(qrCodeImageAsBase64); }
private void btnGenerateQRcode_Click(object sender, EventArgs e) { string strCode = "Hello World"; if (!String.IsNullOrEmpty(txtASCII.Text)) { strCode = txtASCII.Text; } QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); pictureBoxQRCode.Image = qrCodeImage; }
void tbInput_Validated(object sender, EventArgs e) { string data; TextBox tb = sender as TextBox; if (tb != null) { data = tb.Text; if (Utilities.IsLabelValid(data)) { this.tbDate.Text = Utilities.Parselabel_GeDate(data); this.tbModelNumber.Text = Utilities.Parselabel_GetModel(data); this.tbSerialNumber.Text = Utilities.Parselabel_GetSerialNumber(data); // Trace.WriteLine("here"); // #@CE1000@$LE389884$%29122015%# Clipboard.SetData(DataFormats.Text, tbModelNumber.Text + "," + tbSerialNumber.Text); // using (QRCodeGenerator qrcg = new QRCodeGenerator()) { // qrcg.CreateQrCode // } // QRCoder.QRCodeGenerator. if (qrgen == null) { qrgen = new QRCodeGenerator(); } #if false Bitmap bmp; using (QRCodeData qrCodeData = qrgen.CreateQrCode(data, QRCodeGenerator.ECCLevel.H)) { using (QRCode qrCode = new QRCode(qrCodeData)) { bmp = new Bitmap( qrCode.GetGraphic(20, Color.Black, Color.White, true), new Size(64, 64)); writeQRImage(akey, outPath, fmts, bmp); } } #endif } } }
public byte[] cargarDatos(string dato) { var crypt = new SimpleInteroperableEncryption(ConfigurationManager.AppSettings["MetodoEncriptacion"].ToString()); var datoEncriptado = crypt.Encrypt(dato); QRCoder.QRCodeGenerator qRCodeGenerator = new QRCoder.QRCodeGenerator(); QRCoder.QRCodeData qRCodeData = qRCodeGenerator.CreateQrCode(datoEncriptado, QRCoder.QRCodeGenerator.ECCLevel.Q); QRCoder.QRCode qRCode = new QRCoder.QRCode(qRCodeData); //transformamos en bits Bitmap bmp = qRCode.GetGraphic(7); using (MemoryStream ms = new MemoryStream()) { //importante para generar el qr bmp.Save(ms, ImageFormat.Bmp); //row.CodigoQR = ms.ToArray(); return(ms.ToArray()); } }
private void CreateQRCode(object sender, RoutedEventArgs e) { // 生成二维码的内容 MainWindow mainwin = (MainWindow)Application.Current.MainWindow; string strCode = Setting.BASE_URL + "pdf/"; if (Type == 1) { Boolean isSuccess = false; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("uid", mainwin.User.id.ToString()); string url = Setting.BASE_URL + "test/getOverallReport"; string rtext = HttpRequestHelper.HttpGet(url, parameters, ref isSuccess); strCode += No + "overall.pdf"; } else { Boolean isSuccess = false; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("uid", mainwin.User.id.ToString()); parameters.Add("tid", No); string url = Setting.BASE_URL + "test/getSingleReport"; string rtext = HttpRequestHelper.HttpGet(url, parameters, ref isSuccess); strCode += mainwin.User.id + No + "test.pdf"; } url = strCode; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); MemoryStream stream = new MemoryStream(); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, false); qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png); ImageBrush imageBrush = new ImageBrush(); ImageSourceConverter imageSourceConverter = new ImageSourceConverter(); QRCode.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream); }
private async Task <Byte[]> CreateRefraQrCode(string v) { return(await Task <Byte[]> .Run(() => { QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(v, QRCoder.QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap refraIcon = GetRefraLogo().Result; //(Bitmap)Bitmap.FromFile(""); // https://www.refra.com/img/icon/favicon-196x196.png //Bitmap qrCodeImage = qrCode.GetGraphic(20, "#ff4c02", "#000000", true); //Color darColor = System.Drawing.ColorTranslator.FromHtml("#ff4c02"); Color darColor = System.Drawing.ColorTranslator.FromHtml("#000000"); Color lightColor = System.Drawing.ColorTranslator.FromHtml("#ffffff"); Bitmap qrCodeImage = qrCode.GetGraphic(20, darColor, lightColor, refraIcon, 10, 5, true); using (var stream = new MemoryStream()) { qrCodeImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png); Byte[] byteBild = stream.ToArray(); return byteBild; } })); }
public ActionResult CreateCode(string key) { // 生成二维码的内容 string strCode = string.Format("{0}{1}{2}", @"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8e37ff182337cd1f&redirect_uri=http%3a%2f%2frodman.nat300.top%2fapi%2fwchart%2fCodeLogin&response_type=code&scope=snsapi_userinfo&state=", key, @"&connect_redirect=1#wechat_redirect"); QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); // 如果想保存图片 可使用 qrCodeImage.Save(filePath); //// 响应类型 //context.Response.ContentType = "image /Jpeg"; ////输出字符流 //context.Response.BinaryWrite(ms.ToArray()); return(File(ms.ToArray(), "image/Jpeg")); }
public static Bitmap CreateQRcode(string Message) { // 生成二维码的内容 string strCode = Message; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); return(qrCodeImage); // 如果想保存图片 可使用 qrCodeImage.Save(filePath); //// 响应类型 //Context.Response.ContentType = "image/Jpeg"; ////输出字符流 //context.Response.BinaryWrite(ms.ToArray()); }
/// <summary> /// 创建二维码返回Base64字符串 /// </summary> /// <param name="plainText">二维码内容</param> public static string CreateQRCodeToBase64(string plainText, bool hasEdify = true) { try { string result = ""; if (String.IsNullOrEmpty(plainText)) { return(""); } QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); //QRCodeGenerator.ECCLevel:纠错能力,Q级:约可纠错25%的数据码字 QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); if (hasEdify) { result = "data:image/jpeg;base64," + Convert.ToBase64String(arr); } else { result = Convert.ToBase64String(arr); } return(result); } catch (Exception ex) { throw new Exception("创建二维码返回Base64字符串方法异常", ex); } }
protected void Page_Load(object sender, EventArgs e) { // string strCode = File.ReadAllText(Server.MapPath("/csharpDemo2/test.doc"),Encoding.UTF8); string strCode = "data:image/png;base64," + ImgToBase64String(Server.MapPath("/FileDemo/100.jpg")); QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); //qrCodeImage.Save(Server.MapPath("/csharpDemo2/code.jpg")); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "image/Jpeg"; HttpContext.Current.Response.BinaryWrite(ms.ToArray()); HttpContext.Current.Response.End(); }
private void RefreshQRCode() { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://passport.bilibili.com/qrcode/getLoginUrl"); myRequest.CookieContainer = new CookieContainer(); //将请求的结果发送给客户端(界面、应用) HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); cookie = myResponse.Headers.Get("Set-Cookie"); string callback = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8).ReadToEnd(); JSONCallback.QRUrl.QRUrl json = JsonConvert.DeserializeObject <JSONCallback.QRUrl.QRUrl>(callback); if (json.code == 0) { oathkey = json.data.oauthKey; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(json.data.url, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(6, Color.Black, Color.White, null, 15, 6, true); QRCodePicBox.Image = qrCodeImage; materialLabel1.Text = "请使用哔哩哔哩客户端扫码登录或扫码下载APP"; timer1.Start(); } }
/// <summary> /// 生成带参数二维码 /// </summary> /// <returns></returns> public static bool GetOauthCode(string code, string filePath) { try { // 生成二维码的内容 QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); // 如果想保存图片 可使用 qrCodeImage.Save(filePath + code + ".jpg"); return(true); } catch (Exception ex) { _logerror.Error("生成二维码异常:" + ex.Message); return(false); } }
public ActionResult GetBindWeChatImg() { //查询在系统里面的用户信息 var user = new User() { Id = 1, UserName = "******" }; string authorizeCode = Guid.NewGuid().ToString(); //将用户信息和唯一标志绑定 bindWechatDictionary.Add(authorizeCode, user); //生成二维码 string url = $"{authorizeUrl}/weixin/GetWechatUserInfoInterfaceForBindWeChat?authorizeCode={authorizeCode}"; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(5, Color.Black, Color.White, null, 15, 6, false); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, ImageFormat.Jpeg); return(File(ms.ToArray(), "image/jpeg")); }
public static Image GenerateQRCode(byte[] data, int ppm = 4) { using (var generator = new QRCodeGenerator()) using (var qr_data = generator.CreateQRCode(data)) using (var qr_code = new QRCode(qr_data)) return qr_code.GetGraphic(ppm); }
/// <summary> /// Excel导出 /// </summary> /// <param name="keyValuePairs">字典表【名称,数据】</param> /// <param name="sWebRootFolder">网站根文件夹</param> /// <param name="tuple">item1:The virtual path of the file to be returned.|item2:The Content-Type of the file</param> public static void Export(Dictionary <string, DataTable> keyValuePairs, string sWebRootFolder, out Tuple <string, string> tuple) { if (string.IsNullOrWhiteSpace(sWebRootFolder)) { tuple = Tuple.Create("", Excel); } string sFileName = $"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xlsx"; var savePath = Path.Combine(sWebRootFolder, sFileName); if (!Directory.Exists(Path.GetDirectoryName(savePath))) { Directory.CreateDirectory(Path.GetDirectoryName(savePath)); } FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); using (ExcelPackage package = new ExcelPackage(file)) { foreach (var item in keyValuePairs) { string worksheetTitle = item.Key; //表名称 var dt = item.Value; //数据表 // 添加worksheet ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(worksheetTitle); var jColumns = 0; for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { if (i == 0) { //添加表头 worksheet.Cells[1, j + 1].Value = dt.Columns[j].ColumnName; worksheet.Cells[1, j + 1].Style.Font.Bold = true; //字体为粗体 worksheet.Cells[1, j + 1].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; //水平居中 worksheet.Cells[1, j + 1].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; //设置样式类型 worksheet.Cells[1, j + 1].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(159, 197, 232)); //设置单元格背景色 } else { if (dt.Columns[j].ColumnName == "二维码") { if (!string.IsNullOrEmpty(dt.Rows[i][j].ToString())) { using (QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator()) { //QRCodeGenerator.ECCLevel:纠错能力,Q级:约可纠错25%的数据码字 QRCodeData qrCodeData = qrGenerator.CreateQrCode(dt.Rows[i][j].ToString(), QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrcode.GetGraphic(15); using (MemoryStream stream = new MemoryStream()) { qrCodeImage.Save(stream, ImageFormat.Jpeg); byte[] bytes = new byte[stream.Length]; stream.Seek(0, SeekOrigin.Begin); stream.Read(bytes, 0, System.Convert.ToInt32(stream.Length)); System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.Drawing.Bitmap myimge = new System.Drawing.Bitmap(ms); ExcelPicture picture = worksheet.Drawings.AddPicture(Common.GuId(), myimge); //插入图片 worksheet.Row(i + 1).Height = 80.00D; picture.SetPosition(i, 5, 24, 5); //设置图片的位置 picture.SetSize(80, 80); //设置图片的大小 } } } jColumns = j + 1; } else { //添加值 worksheet.Cells[i + 1, j + 1].Value = dt.Rows[i][j].ToString(); } worksheet.Cells[i + 1, j + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; //水平居中 worksheet.Cells[i + 1, j + 1].Style.VerticalAlignment = ExcelVerticalAlignment.Center; //垂直居中 //worksheet.Row(i+1).Height = 85;//设置行高 } } } if (jColumns == 0) { //自动列宽 worksheet.Cells.AutoFitColumns(); } else { //自动列宽 worksheet.Cells.AutoFitColumns(); worksheet.Column(jColumns).Width = 20.00D;//设置列宽 } } package.Save(); } tuple = Tuple.Create(sFileName, Excel); }
private void renderQR(string msg) { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode= qrGenerator.CreateQrCode(msg, QRCodeGenerator.ECCLevel.L); codebox.BackgroundImage = qrCode.GetGraphic(8); }
// QR7 Utility public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1) { byte[] data = QR7.GenerateQRData(pk7, box, slot, num_copies); using (var generator = new QRCodeGenerator()) using (var qr_data = generator.CreateQRCode(data)) using (var qr_code = new QRCode(qr_data)) return qr_code.GetGraphic(4); }
private ApiResult GenerateQrCodeImg(QrCodeDataModel model, out UserFileInfo jpgFile, out UserFileInfo svgFile) { var fileNameRaw = $"{model.Data}_{model.Margin}_{model.Icon}_{model.LightColor}_{model.DarkColor}_{model.Size}"; var fileName = $"{fileNameRaw.ToMd5()}"; var imgFileName = $"{fileName}.jpg"; var svgFileName = $"{fileName}.svg"; UserFile iconFileRaw = null; if (model.Icon?.FileName != null) { Guid.TryParse(model.Icon.FileName, out var fid); if (fid != Guid.Empty) { iconFileRaw = _fileServices.Download(fid); } } Bitmap icon = null; if (iconFileRaw != null) { using (var iconMs = new MemoryStream(iconFileRaw.Data)) { icon = new Bitmap(iconMs); } } jpgFile = _fileServices.Load(QRCodePath, imgFileName); svgFile = _fileServices.Load(QRCodePath, svgFileName); if (jpgFile != null && svgFile != null) { return(null); } if (model == null) { return(ActionStatusMessage.StaticMessage.QrCode.NoData); } var rawText = model.Data; if (rawText == null) { return(ActionStatusMessage.StaticMessage.QrCode.NoData); } var qrCodeData = new QRCoder.QRCodeGenerator().CreateQrCode(rawText, QRCodeGenerator.ECCLevel.H); var svg = new SvgQRCode(qrCodeData).GetGraphic(model.Size, model.DarkColor, model.LightColor, true, SvgQRCode.SizingMode.ViewBoxAttribute); var bitmap = new QRCode(qrCodeData).GetGraphic(model.Size, ColorTranslator.FromHtml(model.DarkColor), ColorTranslator.FromHtml(model.LightColor), icon, model.Icon?.IconSize ?? 15, model.Icon?.BorderSize ?? 6, model?.Margin ?? false); if (jpgFile == null) { using (MemoryStream stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Jpeg); var imgf = new FormFile(stream, 0, stream.Length, imgFileName, imgFileName); jpgFile = _fileServices.Upload(imgf, QRCodePath, imgFileName, Guid.Empty, Guid.Empty).Result; } } if (svgFile == null) { using (var sr = new MemoryStream()) { sr.Write(Encoding.UTF8.GetBytes(svg)); var svgf = new FormFile(sr, 0, sr.Length, svgFileName, svgFileName); svgFile = _fileServices.Upload(svgf, QRCodePath, svgFileName, Guid.Empty, Guid.Empty).Result; } } return(null); }
private void renderQRCode() { QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(textBoxQRCode.Text, QRCodeGenerator.ECCLevel.M); pictureBoxQRCode.BackgroundImage = qrCode.GetGraphic(20); }
public void OnShowQRCode(object sender, DynamicMenuEventArgs e) { var key = e.Tag as string; if (key == null) { return; } var pe = host.MainWindow.GetSelectedEntry(true); if (pe == null) { return; } var context = new SprContext(pe, host.Database, SprCompileFlags.All); var value = SprEngine.Compile(pe.Strings.GetSafe(key).ReadString(), context); try { var data = new QRCodeGenerator().CreateQrCode(value, QRCodeGenerator.ECCLevel.L); if (data != null) { var form = new ShowQRCodeForm( host, data.GetBitmap(10, Color.Black, Color.White), SprEngine.Compile(pe.Strings.GetSafe(PwDefs.TitleField).ReadString(), context), TryTranslateKey(key) ); form.ShowDialog(); } } catch { MessageBox.Show("The data can't be displayed as a QR Code."); } }
private void btnAdd_Click(object sender, EventArgs e) { if (this.txtmasp.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtmasp, "Nhập mã sản phẩm"); return; } else if (SPController.getSanPham(this.txtmasp.Text) != null) { this.errorProvider1.SetError(this.txtmasp, "Mã Sản Phẩm Đã Tồn Tại"); return; } else if (this.txttensp.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txttensp, "Nhập tên Sản Phẩm"); return; } else if (this.txtgiasp.Text.Trim().Length <= 0) { this.errorProvider1.SetError(this.txtgiasp, "Nhập giá sản phẩm"); return; } else if (Convert.ToDateTime(dtpngayin.Value.ToString()) <= Convert.ToDateTime(DateTime.Today.ToString())) { this.errorProvider1.SetError(this.dtpngayin, "Ngày in phải nhỏ hơn hoặc bằng ngày hiện tại"); return; } else { SanPham sanpham = new SanPham(); sanpham.MaSanPham = this.txtmasp.Text.Trim(); sanpham.TenSanPham = this.txttensp.Text.Trim(); sanpham.GiaSanPham = this.txtgiasp.Text.Trim(); sanpham.NgayIn = this.dtpngayin.Value; ListViewItem information = new ListViewItem(this.ID.ToString()); information.SubItems.Add(new ListViewItem.ListViewSubItem(information, txtmasp.Text)); information.SubItems.Add(new ListViewItem.ListViewSubItem(information, txttensp.Text)); information.SubItems.Add(new ListViewItem.ListViewSubItem(information, txtgiasp.Text)); information.SubItems.Add(new ListViewItem.ListViewSubItem(information, dtpngayin.Value.ToString())); this.listInformation.Items.Add(information); Bitmap bm = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height); this.pictureBox1.DrawToBitmap(bm, this.pictureBox1.ClientRectangle); this.pictureBox1.CreateGraphics().Clear(Color.White); bm = new Bitmap(this.pictureBox1.Width + 2, this.pictureBox1.Height + 2); if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); pictureBox1.Image = null; } //In ma 3D QRCoder.QRCodeGenerator qr = new QRCoder.QRCodeGenerator(); var data = qr.CreateQrCode(txttensp.Text, QRCoder.QRCodeGenerator.ECCLevel.H); var code = new QRCoder.QRCode(data); pictureBox1.Image = code.GetGraphic(5); MemoryStream stream = new MemoryStream(); code.GetGraphic(5).Save(stream, ImageFormat.Jpeg); sanpham.ImgQCode = stream.ToArray(); //In ma 2D string barcode = txttensp.Text; try { Zen.Barcode.Code128BarcodeDraw br = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum; pictureBox2.Image = br.Draw(barcode, 40); MemoryStream stream1 = new MemoryStream(); br.Draw(barcode, 40).Save(stream1, ImageFormat.Jpeg); sanpham.Img1D = stream1.ToArray(); } catch (Exception ex) { } if (SPController.AddSanPham(sanpham) == false) { MessageBox.Show("Lỗi thêm user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } txttensp.Text = string.Empty; txtmasp.Text = string.Empty; txtgiasp.Text = string.Empty; dtpngayin.Value = DateTime.Now; this.errorProvider1.Clear(); DisPlayInformation(); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string result = ""; string type = ""; string total = ""; int pageSize = 2; try { string poststr = getpost(); if (!string.IsNullOrEmpty(poststr)) { JObject jobj = JObject.Parse(poststr); type = jobject(jobj, "type"); string namevalue = jobject(jobj, "name"); string contendvalue = jobject(jobj, "content"); string pageNow = jobject(jobj, "pageNow"); string id = jobject(jobj, "id"); switch (type) { case "liuyan": break; case "all": DataTable dt = gettoMsg(pageNow); total = dt.Rows.Count.ToString(); result = "{\"code\":\"0\",\"total\" :\"" + total + "\",\"data\":" + DataTableToJson(dt) + "}"; break; case "search": string bstructure = " id|name|creditCode|regStatus|regDate"; string sql = ArrayKeyWord(contendvalue, bstructure); DataTable dtMsg = ShowMsg(sql); total = dtMsg.Rows.Count.ToString(); result = "{\"code\":\"0\",\"total\" :\"" + total + "\",\"data\":" + DataTableToJson(dtMsg) + "}"; break; case "byId": DataTable dt_id = SearchById(id); total = dt_id.Rows.Count.ToString(); result = "{\"code\":\"0\",\"total\" :\"" + total + "\",\"data\":" + DataTableToJson(dt_id) + "}"; break; case "dele": string[] RegisterCodes = new string[5] { "9", "8", "4", "6", "3" }; var flag = true; var registerCodesStr = string.Empty; foreach (var registerCode in RegisterCodes) { if (string.IsNullOrEmpty(registerCode)) { continue; } var workoreder = registerCode; if (!flag || workoreder == null) { registerCodesStr += registerCode + " ; "; flag = false; continue; } if (int.Parse(registerCode) > 5) { flag = true; } else { flag = false; } if (flag == false) { registerCodesStr += registerCode; continue; } } if (!string.IsNullOrEmpty(registerCodesStr)) { Console.WriteLine("不成功的有:" + registerCodesStr); } break; case "getname": string urls = "http://*****:*****@"DownLoad\"; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000; var r1 = new Random().Next(9); var r2 = new Random().Next(9); var r3 = new Random().Next(9); var r4 = new Random().Next(9); var r = r1 + r2 + r3 + r4; string filePath; //只能使用xls格式的excel文件 filePath = dirPath + epoch + r + ".txt"; FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); fs.Write(results.ResultByte, 0, results.ResultByte.Length); fs.Flush(); fs.Close(); break; case "list": string dataSource = "phone=15015051037"; var url = "https://www.e-irobot.com/api/get_phone"; // 使用ASCII码字符 byte[] datalogins = Encoding.ASCII.GetBytes(dataSource); HttpWebRequest res = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); res.Method = "Post"; res.ContentType = "application/x-www-form-urlencoded"; res.ContentLength = datalogins.Length; Stream newstream = res.GetRequestStream(); newstream.Write(datalogins, 0, datalogins.Length); newstream.Close(); //接收相应 HttpWebResponse resp = (HttpWebResponse)res.GetResponse(); Stream respStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(respStream, Encoding.UTF8); string resultsss = reader.ReadToEnd(); reader.Close(); res.Abort(); ////发送信息 //WebRequest req = WebRequest.Create(url); //req.Method = "post"; //req.ContentType = "application/x-www-form-urlencoded"; //req.CookieContainer = cookies;//设置cookies ////Accept - Language:zh - CN,zh; q = 0.8 //req.Headers.Add("Accept-Language", "zh - CN,zh; q = 0.8"); ////指定客户端代理的方式 ////req.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2560.0 Safari/537.36"); ////添加Post参数 //Stream reqStream = req.GetRequestStream(); //reqStream.Write(data, 0, data.Length); //reqStream.Close(); ////接收相应 //HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //Stream respStream = resp.GetResponseStream(); //StreamReader reader = new StreamReader(respStream, Encoding.UTF8); //string resultsss = reader.ReadToEnd(); //reader.Close(); break; case "excel": try { SqlDbOperHandler doh = new SqlDbOperHandler(); doh.Reset(); doh.SqlCmd = "select from Table_yan"; DataTable excelTab = doh.GetDataTable(); ExportExcel(excelTab); } catch (Exception ex) { WriteLog(ex, "C:\\Users\\Amazinghua\\Desktop\\log.txt"); } break; case "datatable": //excel读入内存表,批量插入数据库 string path = System.Web.HttpContext.Current.Server.MapPath("~/excel/"); string path_zip = path + "gs_0805.xls"; //目标文件 //DataTable fakeTable = ReadExcelToDataTable(path_zip); //BatchInsertBySqlBulkCopy(fakeTable, "gs_0805"); FileInfo fi = new FileInfo(path_zip); string test = (fi.Length / 1024).ToString(); if (int.Parse(test) <= 2) { } else { } break; case "gstest": break; } } } catch (Exception ex) { WriteLog(ex, "C:\\Users\\Amazinghua\\Desktop\\log.txt"); } context.Response.Write(result); context.Response.End(); }
/// <summary> /// 添加车票信息到图片并存放 /// </summary> /// <param name="tickInfo"></param> public static Image MakeTrainTickImage(TrainTicketInfo tickInfo) { if (tickInfo.logid == null) { return(null); } if (TrainTicket.BaseTicketImage == null) { try { TicketImageTool.LoadAllBaseTrainTicketsImage(); } catch { MessageBox.Show("车票模板为空:" + TrainTicket.BaseTickfilePath + "\n" + "请检查是否含有车票模板", "车票目录", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); System.Diagnostics.Process.Start(TrainTicket.BaseTickfilePath); } return(null); } var ticketnumber = new Random().Next(0, TrainTicket.BaseTicketImage.Count); var image = TrainTicket.BaseTicketImage[ticketnumber]; //Console.WriteLine(image.Width + " " + image.Height); Bitmap bitmap = new Bitmap(image, image.Width, image.Height); Graphics g = Graphics.FromImage(bitmap); //cutImage(image, new Point(136,69),50,30); //字体矩形位置 : //x = 图片的长度的中心位置 - 字体长度的一半 - 字行距 //y = 图片的高度的中心位置 - 字体大小的一半 - 偏移(去掉偏移,是居中位置) string year = null; if (tickInfo.date.Length >= 4) { year = tickInfo.date[0].ToString() + tickInfo.date[1].ToString() + tickInfo.date[2].ToString() + tickInfo.date[3].ToString();//年 } string moth = null; if (tickInfo.date.Length >= 7) { moth = tickInfo.date[5].ToString() + tickInfo.date[6].ToString();//月 } string day = null; if (tickInfo.date.Length >= 10) { day = tickInfo.date[8].ToString() + tickInfo.date[9].ToString();//日 } string fickrates = null; if (tickInfo.ticket_rates.Contains("¥")) { fickrates = tickInfo.ticket_rates.Replace("¥", string.Empty); } string Rates = null; if (fickrates != null && fickrates.Contains("元")) { Rates = fickrates.Replace("元", string.Empty); } string Start_Station = null; string Start_Stationpinyin = null; if (!String.IsNullOrWhiteSpace(tickInfo.starting_station)) { Start_Station = tickInfo.starting_station.Remove(tickInfo.starting_station.Length - 1); Start_Stationpinyin = PingYinHelper.GetPinyin(tickInfo.starting_station.Remove(tickInfo.starting_station.Length - 1)); } string destination_Station = null; string Des_Stationpinyin = null; if (!String.IsNullOrWhiteSpace(tickInfo.destination_station)) { destination_Station = tickInfo.destination_station.Remove(tickInfo.destination_station.Length - 1); Des_Stationpinyin = PingYinHelper.GetPinyin(tickInfo.destination_station.Remove(tickInfo.destination_station.Length - 1)); } string S_station = null; string D_station = null; int S_pinyinaddX = 0; int D_pinyinaddX = 0; int max_pinyinmove_length = 9; bool D_ISLongPinyin = false; bool S_ISLongPinyin = false; if (Start_Stationpinyin != null && Start_Stationpinyin.Length <= max_pinyinmove_length) { S_pinyinaddX = 42 - Start_Stationpinyin.Length; } else { S_ISLongPinyin = true; } if (Des_Stationpinyin != null && Des_Stationpinyin.Length <= max_pinyinmove_length) { D_pinyinaddX = 42 - Des_Stationpinyin.Length; } else { D_ISLongPinyin = true; } if (Start_Station != null && Start_Station.Length <= 2) { S_station += Start_Station[0]; S_station += " "; S_station += Start_Station[1]; } else { S_station = Start_Station; } if (destination_Station != null && destination_Station.Length <= 2) { D_station += destination_Station[0]; D_station += " "; D_station += destination_Station[1]; } else { D_station = destination_Station; } string IDinfo = null; char addidinfo; for (int i = 0; i < tickInfo.ID.Length; i++) { if (i >= 10 && i <= 13) { addidinfo = '*'; } else { addidinfo = tickInfo.ID[i]; } IDinfo += addidinfo; } var reduce = new Random().Next(0, 20); AddInfoToImage(tickInfo.ticket_num, g, 40, "arial.ttf", 50, 35 - reduce, RedBrush, FontStyle.Bold); AddInfoToImage(tickInfo.jianpiao, g, 32, 680, 20, blackBrush); AddInfoToImage(S_station, g, 41, 110, 80, blackBrush); if (Start_Stationpinyin != null) { if (S_ISLongPinyin) { AddInfoToImage(Start_Stationpinyin, g, 30, "标准仿宋体简.ttf", 110 + Start_Stationpinyin.Length + S_pinyinaddX, 140, blackBrush, FontStyle.Regular, 0.8f, 1); } else { AddInfoToImage(Start_Stationpinyin, g, 30, "标准仿宋体简.ttf", 110 + Start_Stationpinyin.Length + S_pinyinaddX, 140, blackBrush); } } AddInfoToImage("站", g, 30, 290, 90, blackBrush); AddInfoToImage(D_station, g, 41, 600, 80, blackBrush); if (Des_Stationpinyin != null) { if (D_ISLongPinyin) { AddInfoToImage(Des_Stationpinyin, g, 30, "标准仿宋体简.ttf", 600 + Des_Stationpinyin.Length + D_pinyinaddX, 140, blackBrush, FontStyle.Regular, 0.8f, 1); } else { AddInfoToImage(Des_Stationpinyin, g, 30, "标准仿宋体简.ttf", 600 + Des_Stationpinyin.Length + D_pinyinaddX, 140, blackBrush); } } AddInfoToImage("站", g, 30, 780, 90, blackBrush); //////////////////////////////////////////////// if (tickInfo.train_num.Length < 4) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 400 + 20 - tickInfo.train_num.Length, 80, blackBrush); } else if (tickInfo.train_num.Length == 4) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 408, 80, blackBrush); } else if (tickInfo.train_num.Length == 5) { AddInfoToImage(tickInfo.train_num, g, 40, "车次.ttf", 392, 80, blackBrush); } ///////////////////////////////////////////////////////////////// AddInfoToImage(tickInfo.train_che, g, 32, "TechnicBold.ttf", 587, 182, blackBrush); AddInfoToImage("车", g, 20, 637, 195, blackBrush); AddInfoToImage(tickInfo.train_hao, g, 32, "TechnicBold.ttf", 660, 182, blackBrush); AddInfoToImage("号", g, 20, 732, 195, blackBrush); //AddInfoToImage("限乘当日当次车", g, 9, 20, 110, blackBrush); ////////////////////////////////////////////////// AddInfoToImage("网", g, 27, 400, 242, blackBrush); AddInfoToImage(tickInfo.seat_category, g, 25, 642, 240, blackBrush); AddInfoToImage(year, g, 34, "TechnicBold.ttf", 79, 182, blackBrush, FontStyle.Regular); AddInfoToImage("年", g, 20, 170, 195, blackBrush); AddInfoToImage(moth, g, 34, "TechnicBold.ttf", 200, 182, blackBrush, FontStyle.Regular); AddInfoToImage("月", g, 20, 255, 195, blackBrush); AddInfoToImage(day, g, 34, "TechnicBold.ttf", 285, 182, blackBrush, FontStyle.Regular); AddInfoToImage("日", g, 20, 337, 195, blackBrush); AddInfoToImage(tickInfo.train_starttime, g, 34, "TechnicBold.ttf", 376, 182, blackBrush, FontStyle.Bold); AddInfoToImage("开", g, 20, 480, 195, blackBrush); //AddInfoToImage("¥", g, 31, "华文宋体.ttf", 80, 240, blackBrush); AddInfoToImage(Rates, g, 33, "TechnicBold.ttf", 119, 240, blackBrush); int yuan_X = 0; if (Rates != null && Rates.Length > 4) { yuan_X += 25; } AddInfoToImage("元", g, 20, 205 + yuan_X, 250, blackBrush); // AddInfoToImage(tickInfo.ticket_num, g, 13, 20, 9, RedBrush); AddInfoToImage(tickInfo.name, g, 31, 460f, 397f, blackBrush); AddInfoToImage(IDinfo, g, 33.5f, "TechnicBoldshort.ttf", 78f, 397f, blackBrush); //AddInfoToImage(tickInfo.bottomid, g, 25f, 80f, 560f, blackBrush,FontStyle.Bold,1f,2f); AddInfoToImage(tickInfo.bottomid, g, 20f, "仿宋_GB2312.ttf", 90f, 560f, blackBrush, FontStyle.Regular, 1.147f, 1.6f); AddInfoToImage(Start_Station, g, 27f, 440f, 560f, blackBrush, FontStyle.Bold); int Shou_X = 0; if (Start_Station != null && Start_Station.Length <= 2) { Shou_X -= 38; } AddInfoToImage("售", g, 27f, 550f + Shou_X, 560f, blackBrush, FontStyle.Bold); string strCode = string.Format("网络异常\n车票读取信息为{0}\n{1}\n{2}→{3}\n{4}年{5}月{6}日{7}\n{8}车{9}号\n{10}", tickInfo.ticket_num, tickInfo.train_num, S_station, D_station, year, moth, day, tickInfo.train_starttime, tickInfo.train_che, tickInfo.train_hao, tickInfo.name); // string strCode = "https://www.12306.cn/index/"; QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(strCode, QRCodeGenerator.ECCLevel.Q); QRCode qrcode = new QRCode(qrCodeData); // qrcode.GetGraphic 方法可参考最下发“补充说明” Bitmap qrCodeImage = qrcode.GetGraphic(3, Color.FromArgb(160, 0, 0, 0), Color.FromArgb(0, 0, 0, 0), null, 16, 6, false); AddImageToImage(g, ResizeImage(qrCodeImage, qrCodeImage.Width - 12, qrCodeImage.Height), new Point(735, 377)); var FinalImage = byteToImage(Bitmap2Byte(bitmap)); //"售" //bitmap.Save(TrainTicket.savePath + tickInfo.GetHashCode() + ".jpg", ImageFormat.Jpeg); //TrainTicket.TrainTicketImages.Add(byteToImage(Bitmap2Byte(bitmap))); g.Dispose(); bitmap.Dispose(); //image.Dispose(); return(FinalImage); }
public ActionResult GenerateAuthQrCode(string key) { var ProvisionUrl = string.Format("otpauth://totp/{0}:{1}?secret={2}", Config.Title, User.Identity.Name, key); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(ProvisionUrl, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); return File(Helpers.Utility.ImageToByte(qrCodeImage), "image/png"); }