【问题标题】:External images not loading in RDLC report: Windows Forms Application VB.netRDLC 报告中未加载外部图像:Windows 窗体应用程序 VB.net
【发布时间】:2020-12-06 01:07:23
【问题描述】:

我正在开发一个 Windows 窗体应用程序,使用 vb.net 和 microsoft sql server 作为后端。至于报告,我使用的是 microsoft 的 rdlc,这对我来说非常满意,直到我遇到这个明显的问题。

因此,在报告中,我使用了通过本地文件路径加载并作为参数传递的外部图像。我从数据库中检索这些路径并将其传递给报告。这种方法对我有用很长时间,直到它停止工作。现在的情况是,报告中没有加载外部图像(显示的是红十字而不是图像)。就我而言,这个问题与我的 PC 上的权限有关,因为相同的代码和配置以前对我有用,但我无法解决它。我到处搜索,没有尽头,肯定需要帮助。

我的报告代码是:

  Try
            With Me.ReportViewer1.LocalReport
                .DataSources.Clear()
                .ReportPath = Application.StartupPath & "\RptArticle.rdlc"
                
                .EnableExternalImages = True


                Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
                Dim imgparameter As New ReportParameter
                imgparameter = New ReportParameter("ImagePath", "file://" & imagepathstring, True)
                .SetParameters(imgparameter)


                Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
                Dim barcode As New ReportParameter("Barcode", "file://" & barpathstring, True)
                .SetParameters(barcode)

                .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleAccessory", Accdt))

                .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleSize", AccSdt))

                .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleColour", AccCdt))

                .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticleColour", AccCdt))

                .DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DSArticle", dt))



            End With

            Me.ReportViewer1.ZoomMode = ZoomMode.PageWidth

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        Me.ReportViewer1.RefreshReport()

当我加载报告时,输出是:

警告:如果将报表发布到没有 UnattendedExecutionAccount 的报表服务器或目标图像未启用匿名访问,则不会显示具有外部 URL 引用的图像。 (rsWarningFetchingExternalImages) 警告:图像“Image1”的 MIMEType 属性值是“application/octet-stream”,它不是有效的 MIMEType。 (rsInvalidMIMEType) 警告:图像“Image1”的 ImageData 属性值为“”,这不是有效的 ImageData。 (rsInvalidExternalImageProperty) 警告:图像“Image2”的 MIMEType 属性值为“application/octet-stream”,它不是有效的 MIMEType。 (rsInvalidMIMEType) 警告:图像“Image2”的 ImageData 属性值为“”,这不是有效的 ImageData。 (rsInvalidExternalImageProperty) 线程 0x3948 已退出,代码为 0 (0x0)。

【问题讨论】:

    标签: vb.net visual-studio rdlc


    【解决方案1】:

    您可以将图像作为字符串作为参数传递给报告,而不是使用外部图像。

    首先使用以下方法将您的图像转换为 Base64 字符串:

    Public Function ImageToBase64(ByVal image As Image, ByVal format As System.Drawing.Imaging.ImageFormat) As String
       Dim base64String As String = ""
       Using ms As New System.IO.MemoryStream()
          image.Save(ms, format)
          Dim imageBytes As Byte() = ms.ToArray()
          base64String = Convert.ToBase64String(imageBytes)
       End Using
       Return base64String
    End Function
    

    所以这个:

    Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
    Dim imgparameter As New ReportParameter
    imgparameter = New ReportParameter("ImagePath", "file://" & imagepathstring, True)
    .SetParameters(imgparameter)
    
    
    Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
    Dim barcode As New ReportParameter("Barcode", "file://" & barpathstring, True)
    .SetParameters(barcode)
    

    会是这样的:

    Dim imagepathstring As String = System.IO.Path.Combine(folder & "\ArticlePics", imagepath)
    Dim imgparameter As New ReportParameter
    imgparameter = New ReportParameter("ImagePath", ImageToBase64(Image.FromFile(imagepathstring),<THE IMAGE FORMAT OF YOUR IMAGE>))
    .SetParameters(imgparameter)
    
    
    Dim barpathstring As String = System.IO.Path.Combine(folder & "\BarCode", barpath)
    Dim barcode As New ReportParameter("Barcode", ImageToBase64(Image.FromFile(barpathstring),<THE IMAGE FORMAT OF YOUR IMAGE>))
    .SetParameters(barcode)
    

    然后,在您的报告中设置以下内容:

    ImagePath
    
    MIMEType = select the correct MIME type from the dropdown list
    Source = Database
    Value = <Expression>
    

    在表达式窗口中:

    =System.Convert.FromBase64String(Parameters!ImagePath.Value)
    
    Barcode
    
    MIMEType = select the correct MIME type from the dropdown list
    Source = Database
    Value = <Expression>
    
    =System.Convert.FromBase64String(Parameters!Barcode.Value)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      相关资源
      最近更新 更多