将图像从picturebox分配给rdlc报告

时间:2014-09-11 04:58:34

标签: c# rdlc windows-forms-designer

我想知道是否有可能将我的gui内的Picturebox中的图片添加到rdlc报告中。现在我正在为所有的字符串做这个,但我想添加一张图片。

reportViewer3.Visible = true;

        DataSet2 DsActivityReport = new DataSet2();
        ReportDataSource reportDataSource = new ReportDataSource();
        reportDataSource.Name = "DataSet1";
        reportDataSource.Value = DsActivityReport.Tables[0];


        ReportParameter name = new ReportParameter("NAME", txtNAME.Text);
        ReportParameter employee_id = new ReportParameter("EMPLOYEE_ID", txtEmpNo.Text);
        ReportParameter company_id = new ReportParameter("COMPANY_ID", txtCompany.Text);
        ReportParameter emp_no = new ReportParameter("EMP_NO", txtEmpNo.Text);
        //ReportParameter emp_picture = new ReportParameter("picture", );

        reportViewer3.LocalReport.EnableExternalImages = true;
        reportViewer3.LocalReport.DataSources.Clear();

        reportViewer3.LocalReport.SetParameters(new ReportParameter[] { name, employee_id, company_id, emp_no});
        reportViewer3.LocalReport.DataSources.Add(reportDataSource);

        reportViewer3.RefreshReport();

我真的希望有一些帮助,因为我很丢失..试着整天都这样做,但找不到解决我问题的方法。

我试图这样做:

我的参数值称为图片。 = System.Convert.FromBase64String(参数!picture.Value)

和代码:

 public string ConvertImgToBase64String()
    {
        byte[] arrpic;
        using (MemoryStream ms = new MemoryStream())
        {
            picEmployee.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            arrpic = ms.ToArray();
        }
        string base64String = Convert.ToBase64String(arrpic);
        return base64String;
    }
  ReportParameter Picture = new ReportParameter("picture", ConvertImgToBase64String());

reportViewer3.LocalReport.SetParameters(new ReportParameter[] { name, employee_id, company_id, emp_no, Picture });

但图片没有,并且没有错误消息。

1 个答案:

答案 0 :(得分:0)

Dim arrPic as byte() = /*Load the image as array of byte
Convert byte() to BASE64 */
Dim sIMGBASE64 as String = Convert.ToBase64String(arrPic))
/*Add the BASE64 stream to the parameters*/
paramList1.Add(New ReportParameter(<sparamname>, sIMGBASE64)

在报告中设置&#34;值&#34; Picture Box的财产如下:

Value=System.Convert.FromBase64String(Parameters!<sparamname>.Value)

尝试使用您的代码。