C# 使用资源映像作为RDLC参数中的值

C# 使用资源映像作为RDLC参数中的值,c#,resources,rdlc,C#,Resources,Rdlc,我试图将图像作为参数传递给RDLC报告中的图像。我尝试使用以下方法: string imgPath = new Uri("pack://application:,,,/Resources/default_product_img.png").AbsoluteUri; string imgPath = new Uri(AppDomain.CurrentDomain.BaseDirectory + "pack://application:,,,/Resources/default_product_i

我试图将图像作为参数传递给RDLC报告中的图像。我尝试使用以下方法:

string imgPath = new Uri("pack://application:,,,/Resources/default_product_img.png").AbsoluteUri;

string imgPath = new Uri(AppDomain.CurrentDomain.BaseDirectory + "pack://application:,,,/Resources/default_product_img.png").AbsoluteUri;

string imgPath = new Uri("/Resources/default_product_img.png").AbsoluteUri;

string imgPath = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/Resources/default_product_img.png").AbsoluteUri;

string imgPath = new Uri("pack://application:,,,/Resources/default_product_img.png", UriKind.Absolute).AbsoluteUri;

string imgPath = new Uri(HttpContext.Current.Server.MapPath("~/Resources/default_product_img.png")).AbsoluteUri;

string imgPath = new Uri(HostingEnvironment.MapPath("~/Resources/default_product_img.png")).AbsoluteUri;
但是当我运行它时,显示屏总是显示红色的X。我成功地做到了这一点,但图像的源代码与
.exe处于同一级别,而不是在其内部

我还尝试创建一个
BitmapImage
,但是
ReportParameter()
只接受字符串

有没有办法让这起作用?或者我应该把它复制到
.exe
文件旁边吗

需要注意的事项:

  • 图像源设置为
    External

  • default\u product\u img.png
    位于
    Resources
    文件夹中,并具有
    资源的
    构建操作

  • 参数名称设置为
    使用此图像中的值:


将图像作为位图保存到内存流,然后将内存流转换为base64字符串。将此字符串传递到参数中,并将该参数用作图像。在RDLC中,将图像源设置为数据库,并确保mime类型与将位图保存到内存流的方式正确匹配

string paramValue;
using (var b = new Bitmap("file path or new properties for bitmap")) {
    using (var ms = new MemoryStream()) {
        b.save(ms, ImageFormat.Png);
        paramValue = ConvertToBase64String(ms.ToArray());
    }
}


或者,如果要将其保留为外部文件,请将图像源设置为rdlc中的外部文件,并将图像的路径传递为file://c:\site\resources\default\u product\u img.png,它需要是一个绝对路径,您可以使用Server.MapPath将web相对路径转换为绝对本地路径,然后只需确保同时具有file://即可路径的开头,以便报表引擎知道它是本地路径。

External在使用嵌入exe文件中的图像时无效?我错过了关于它是嵌入资源的部分。然后,我建议使用数据库选项并将其读入位图对象(遵循我回答中的第一个建议)。