第一步:C#定义用于FastReport绑定的图片路径属性
[NotMapped]
public string SignatureImgPath { get; set; }
第二步:SignatureImgPath 路径生成图片
第三步:FastReport模板创建,添加PictureBox
注:添加普通文本绑定SignatureImgPath 属性
第四步:实现数据加载绑定
private void Data1_BeforePrint(object sender, EventArgs e) { string img = Report.GetColumnValue("one.SignatureImgPath").ToString(); Picture1.ImageLocation=img; }
注:隐藏SignatureImgPath 文本框(即图片路径)
其他帮助方法
// <summary> /// 将byte[]输出为图片 /// </summary> /// <param name="path">输出图片的路径及名称</param> /// <param name="picByte">byte[]数组存放的图片数据</param> public void SaveImg(string path, byte[] picByte) { try { FileStream fs = new FileStream(path, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); //开始写入 bw.Write(picByte, 0, picByte.Length); //关闭流 bw.Close(); fs.Close(); } catch (Exception) { throw; } } // <summary> /// 将byte[]输出为图片 /// </summary> /// <param name="path">输出图片的路径及名称</param> /// <param name="byte64String">byte64字符串</param> public void SaveImgByStringByte64(string path, string byte64String) { try { //string base64Str = System.Text.Encoding.Default.GetString(byte64String); //byte[] bytes = Convert.FromBase64String(byte64String); //将base64头部信息替换 string base64Str = byte64String.Replace("data:image/png;base64,", "") .Replace("data:image/jgp;base64,", "") .Replace("data:image/jpg;base64,", "") .Replace("data:image/jpeg;base64,", ""); byte[] picByte = Convert.FromBase64String(base64Str); FileStream fs = new FileStream(path, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); //开始写入 bw.Write(picByte, 0, picByte.Length); //关闭流 bw.Close(); fs.Close(); } catch (Exception) { throw; } }
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!