Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

report viewer pass image from form possible?

Using visual Studio ultimate 2012.

Im currently building a report to be printed in report viewer. so far i have a bunch of text boxes that Gets its values from my form text boxes via parameters.

So far all works fine.

Then I hit a major problem. How do you pass an Image From my images on my form to an image on a report? 1 image pre exists on a database i beleive i can call into the image as a parameter(not sure). the bigger issue is the other image.

The other image uses an external API that generates QR images. this image is displayed in a picture box on my form at runtime. I am not saving the image anywhere i would prefer not too. BUT i understand if i may need to. Is there any way at all i can pass the QR image from the image box on my form to my report Image box?

Update heres the code for the error:

Microsoft.Reporting.WinForms.ReportParameter rpIMG1 = new Microsoft.Reporting.WinForms.ReportParameter("paramQRimg", base64String);
Microsoft.Reporting.WinForms.ReportParameter rpIMG2 = new Microsoft.Reporting.WinForms.ReportParameter("paramQRMi", "image/png");

reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { rp1, rp2, rp3, rp4, rp5, rp6, rp7, rp8, rp9, rp10, rpIMG1, rpIMG2 });

Error occurs on the set Parameters part all it says is:

An error occurred during local report processing.

no idea why it doesn't like this

like image 655
lemunk Avatar asked Nov 15 '12 11:11

lemunk


1 Answers

 public string ImageToBase64(Image image, 
  System.Drawing.Imaging.ImageFormat format)
{
  using (MemoryStream ms = new MemoryStream())
  {
    // Convert Image to byte[]
    image.Save(ms, format);
    byte[] imageBytes = ms.ToArray();

    // Convert byte[] to Base64 String
    string base64String = Convert.ToBase64String(imageBytes);
    return base64String;
  }
}

Convert your image to base64 string and then pass it to your report as parameter and then set the Report image to this parameter.

like image 140
Talha Avatar answered Nov 08 '22 05:11

Talha