工具:FastRepor,VS2015
FastRepor:
1.在FastRepor新建表格添加图片
拖拽到需要编辑的地方,点击编辑加载图片
加载图片
绑定的数据源
类型选择Byte[]
到此为止FastRepor的准备工作完成!
C#:
DataTable dt = new DataTable();
dt.TableName = "TagData";//绑定的数据源名称
ds.Tables.Add(dt);
//绑定的数据源字段,要显示图片数据的字段 (注意byte[]类型)
dt.Columns.Add("Picture2", typeof(byte[])); //图片
byte[] by = Convert.FromBase64String(?)
(?里的数值为图片转的base64数据)
#region base64解码
public static string Base64String(Bitmap img)
{
string Base64="";
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] Base64= new byte[ms.Length];
ms.Position = 0;
ms.Read(Base64, 0, (int)ms.Length);
ms.Close();
Base64= Convert.ToBase64String(Base64);
}
return Base64;
}
#endregion
//将数据赋值到Picture2字段数据源
dt.Rows[i]["Picture2"] = by; //图片
//FastReport文件路径
report.Load(@".\?\?.frx")
report.RegisterData(ds);
report.PrintSettings.ShowDialog = false;
report.Print();//打印报表
report.Dispose();