private void btnCreateQrCode_Click(object sender, EventArgs e) { if (btnCreateQrCode.Text == CREATE_QR_CODE) { if (string.IsNullOrEmpty(tbContent.Text)) { return; } //普通二维码的生成 //Bitmap qrCode = QrCodeWriter.CreateQrCode(tbContent.Text, ImageFormat.Png); //带logo的二维码的生成 string CurrentDirectory = System.IO.Directory.GetCurrentDirectory(); string logoPath = System.IO.Path.Combine(CurrentDirectory, "Resources\\Logo.jpg"); Bitmap Logo = new Bitmap(logoPath); Bitmap qrCode = QrCodeWriter.CreateQrCodeWithLogo(tbContent.Text, Logo, "utf-8", 10, 10); pbQrCode.Image = qrCode; pbQrCode.Visible = true; tbContent.Visible = false; btnSave.Visible = true; btnCreateQrCode.Text = RE_CREATE_QR_CODE; } else { tbContent.Visible = true; pbQrCode.Visible = false; btnCreateQrCode.Text = CREATE_QR_CODE; tbContent.Text = string.Empty; btnSave.Visible = false; tbContent.Focus(); } }
public void CreateQrCode() { string[] Size = SelectCodeSize.Split("*"); int width = int.Parse(Size[0]); int height = int.Parse(Size[1]); if (!MergeCode) { foreach (var item in Datas) { string CodeContent = item.SLId + "_" + item.PBId; string savePath = _outputDir + $"\\{item.SLId}.png"; QrCodeWriter.CreateQrCode(CodeContent, savePath, ImageFormat.Png, "utf-8", width, height); } } else { //将生成的二维码放在一张图上 //暂定一行放五个二维码 int column = 5; List <Bitmap> codeList = new List <Bitmap>(); foreach (var item in Datas) { string CodeContent = item.SLId + "_" + item.PBId; Bitmap code = QrCodeWriter.CreateQrCode(CodeContent, ImageFormat.Png, "utf-8", width, height); codeList.Add(code); } Bitmap newBitmap = MergeBitmaps(codeList, column); string savePath = _outputDir + $"\\testMeger.png"; newBitmap.Save(savePath, ImageFormat.Png); newBitmap.Dispose(); newBitmap = null; codeList.ForEach(X => X.Dispose()); codeList.Clear(); codeList = null; } MessageBox.Show("生成成功"); }