我正在尝试将图像作为参数传递给 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;
Run Code Online (Sandbox Code Playgroud)
但当我运行它时,显示屏总是显示红色 X。我成功地完成了这项工作,但图像的来源与 位于同一级别,.exe而不是在其中。
我也尝试创建一个BitmapImage,但ReportParameter()只接受字符串。
有办法让它发挥作用吗?或者我应该将其复制到.exe文件旁边?
注意事项:
图像源设置为External
default_product_img.png位于Resources文件夹内并且有一个Build ActionofResource
参数名称设置为中的值Use this image:
将图像作为位图保存到内存流中,然后将内存流转换为 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());
}
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您想将其保留为外部文件,请将图像源设置为 rdlc 中的外部,并将图像路径传递为 file://c:\site\resources\default_product_img.png ,它需要是绝对路径路径,您可以使用 Server.MapPath 将 Web 相对路径转换为绝对本地路径,然后只需确保路径开头有 file:// ,以便报表引擎知道它是本地路径。
| 归档时间: |
|
| 查看次数: |
4178 次 |
| 最近记录: |