using CrystalDecisions.CrystalReports.Engine;
using System.Configuration;
using CrystalDecisions.Shared;
using Gma.QrCodeNet.Encoding.Windows.Render;
using Gma.QrCodeNet.Encoding;
using System.IO;
using Gma.QrCodeNet.Encoding.Windows.Forms;
private void button1_Click(object sender, EventArgs e)
{
dt.Columns.Add("A",typeof(byte[]));
dt.Columns.Add("B");
dt.Columns.Add("C");
for (int i = 0; i < 2; i++)
{
DataRow dr = dt.NewRow();
dr["B"] = "1111111111dafadfasdfadsfsdfasdfasdfasdfjlasdfjasl;dfjasdfl;asjdfasl;jdflsadfjsdfaasdfasdf--13123123-adsfasdfkljsdf^sadfsdasadfasdfasdfsadf" + i.ToString();
dr["C"] = "2222222222" + i.ToString();
dr["A"] = GenQrCode(dr["B"].ToString());
dt.Rows.Add(dr);
}
document = new ReportDocument();
string reportPath = @"D:\Prj\DEV\Barcode\20160610\PrintReportSvr\PrintReportSvr\OrderReport\ReportTest.rpt";
document.Load(reportPath);
document.SetDataSource(dt);
document.ExportToDisk(ExportFormatType.PortableDocFormat, pdfPath + @"\" + pdfName);
}
public byte[] GenQrCode(string barcodeContent)
{
byte[] bt = null;
Color _lightModule = Color.White;//Color.FromArgb(220, 100, 203, 50);
Color _darkModule = Color.Black;//Color.FromArgb(170, 20, 250, 220);
QrCodeImgControl qrControl = new QrCodeImgControl();
qrControl.ErrorCorrectLevel = ErrorCorrectionLevel.M;
qrControl.QuietZoneModule = Gma.QrCodeNet.Encoding.Windows.Render.QuietZoneModules.Two;
qrControl.DarkBrush = new SolidBrush(_darkModule);
qrControl.LightBrush = new SolidBrush(_lightModule);
qrControl.Width = 100;
qrControl.Height = 100;
qrControl.Text = barcodeContent;
//qrControl.Image.Save(@"C:\1111\1123.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
bt = GetByteImage(qrControl.Image);
return bt;
}
public byte[] GetByteImage(Image img)
{
byte[] bt = null;
if (!img.Equals(null))
{
using (MemoryStream mostream = new MemoryStream())
{
Bitmap bmp = new Bitmap(img);
bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Jpeg);//将图像以指定的格式存入缓存内存流
bt = new byte[mostream.Length];
mostream.Position = 0;//设置留的初始位置
mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
}
}
return bt;
}