【问题标题】:Image not appearing in rdlc report even when passed as parameter即使作为参数传递,图像也不会出现在 rdlc 报告中
【发布时间】:2018-12-07 12:27:07
【问题描述】:

我正在尝试在 rdlc 报告上显示图像,并且我保存了一个图像对象和一个名为 BoxImage 的参数。

public void Run(string BoxImage, string LogoImage)
{
    try 
    { 
        LocalReport report = new LocalReport();

        var path = System.Windows.Forms.Application.StartupPath;
        log.Info(Path.Combine(path, @"Reporting\QCLabelV2.rdlc"));
        report.ReportPath = Path.Combine(path, @"Reporting\QCLabelV2.rdlc");
        report.EnableExternalImages = true;
        ReportParameter boxImage = new ReportParameter("BoxImage");
        boxImage.Values.Add(BoxImage);
        report.SetParameters(boxImage);

        report.DataSources.Clear();
        report.DataSources.Add(new ReportDataSource("dsList", LoadSalesData()));

        report.Refresh();
        log.Info("Finished Refresh");
        Export(report);
        log.Info("Export Complete");
        Print();
        log.Info("Print Complete");
    }
    catch (Exception ex)
    {

    }
}

这是我的打印功能

private void Print()
{
    ProcessStartInfo info = new ProcessStartInfo();
    info.Verb = "print";
    var path = System.Windows.Forms.Application.StartupPath;
    info.FileName = Path.Combine(path, @"Reporting\BoxLabel.pdf");
    info.CreateNoWindow = true;
    info.WindowStyle = ProcessWindowStyle.Hidden;

    Process p = new Process();
    p.StartInfo = info;
    p.Start();

    p.WaitForInputIdle();
    System.Threading.Thread.Sleep(3000);
    if (false == p.CloseMainWindow())
        p.Kill();
}

这是我生成 pdf 的导出函数。

private void Export(LocalReport report)
{ 

        byte[] Bytes = report.Render(format: "PDF", deviceInfo: "");

        var path = System.Windows.Forms.Application.StartupPath;
        log.Info("About to create file - " + Path.Combine(path, @"Reporting\BoxLabel.pdf"));
        using (FileStream stream = new FileStream(Path.Combine(path, @"Reporting\BoxLabel.pdf"), FileMode.Create))
        {
            stream.Write(Bytes, 0, Bytes.Length);
        }
        path = Properties.Settings.Default.AssemblyLabelLocation;
        log.Info("About to create file - " + Path.Combine(path, _objectList.First().BarcodeValue.Replace("*", "") + " - " + _objectList.First().ProductCode + ".pdf"));
        using (FileStream stream = new FileStream(Path.Combine(path, _objectList.First().BarcodeValue.Replace("*", "") + " - " + _objectList.First().ProductCode + ".pdf"), FileMode.Create))
        {
            stream.Write(Bytes, 0, Bytes.Length);
        }



}

但无论我设置什么,我仍然会在报告中看到一个空白图像。正如你在下面看到的,确实有一张图片!

图像属性的参数设置

【问题讨论】:

  • 数以百万计的 stack 用户难以相信,没有人能给出答案

标签: c# rdlc reportviewer


【解决方案1】:

您使用的似乎是一个文件,所以图像源必须设置为External

您已经设置了ReportViewer.LocalReport.EnableExternalImage = True,所以最后要做的就是传递一个转换为 URI (Convert file path to a file URI?) 的文件路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多