2014-09-11 57 views
0

我想知道是否可以将图片从我的gui中的图片库添加到rdlc报告。现在我为所有的字符串做这个,但我想添加一张图片。将图片从图片库指定到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 }); 

但图像不和没有错误消息。

回答

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) 

在报告设定图片框的这样的“值”属性:

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

你的代码试试这个。

+0

你可以做c#代码吗? :) – grumme25 2014-09-11 06:28:18

+0

是的,我做到了。其工作良好 – mansoor 2014-09-11 06:45:35

+0

我编辑我的问题与新的解决方案,但它仍然给我的问题。 – grumme25 2014-09-11 07:02:50