从形式可能报表查看器通图像? [英] report viewer pass image from form possible?

查看:153
本文介绍了从形式可能报表查看器通图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio最终2012



即时通讯目前在建的报表查看器要打印的报告。到目前为止,我有为数众多的通过参数从我的窗体的文本框中获取其值的文本框。



到目前为止,一切工作正常。



然后我打了一个大问题。你如何通过将图像从我的窗体上的图像在报表上的图像? 1图像预处理存在的数据库我beleive我可以打电话到图像作为参数(不知道)上。更大的问题是其他的形象。



其他图像使用生成的QR图像的外部API。这个图像显示在图片框中我在运行时的形式。
我没有保存图像的任何地方我宁愿不要了。但我明白,如果我需要。 ?有什么办法可言我可以通过从图像框QR像我的表单上我的报告图像框中



更​​新继承人的错误代码:

  Microsoft.Reporting.WinForms.ReportParameter rpIMG1 =新Microsoft.Reporting.WinForms.ReportParameter(paramQRimg,base64String); 
Microsoft.Reporting.WinForms.ReportParameter rpIMG2 =新Microsoft.Reporting.WinForms.ReportParameter(paramQRMi,图像/ PNG);

reportViewer1.LocalReport.SetParameters(新Microsoft.Reporting.WinForms.ReportParameter [] {RP1,RP2,RP3,RP4,RP5,RP6,RP7,RP8,RP9,RP10,rpIMG1,rpIMG2}) ;



发生在设置的参数部分的所有它说是错误:

 本地报表处理过程中出错。 



不知道为什么它不喜欢这种


解决方案

 公共字符串ImageToBase64(图片形象,
System.Drawing.Imaging.ImageFormat格式)
{
按(MemoryStream的毫秒=新的MemoryStream())
{
//图像转换为byte []
image.Save(MS,格式);
字节[] = imageBytes ms.ToArray();

//转换字节[]为Base64字符串
串base64String = Convert.ToBase64String(imageBytes);
返回base64String;
}
}



将您的图像的base64字符串,然后把它传递给你作为参数报告,然后将报告图像此参数。


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

解决方案

 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.

这篇关于从形式可能报表查看器通图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆