【问题标题】:Add image to Crystal reports from vb.net从 vb.net 将图像添加到 Crystal 报表
【发布时间】:2012-01-25 16:39:32
【问题描述】:

我有一个问题,我试图在水晶报告中以编程方式从 vb.net 替换图像。

这就是我的工作:

Dim facturacion As New dtFactura()
rowDatosFactura.Logo = "F:\imgtest.png"
facturacion.DatosFactura.AddDatosFacturaRow(rowDatosFactura)

我将图像路径设置为数据集

然后在te数据集中添加字符串以替换水晶报表中的图像

在 cyrstal 报告下我添加了一个 ole 图片对象

在对象内部我用这个改变了公式

{DatosFactura.Logo}

这是我在图片对象的公式编辑器中拥有的,但是当我运行代码时,它不会替换图像。

我以这种方式生成报告

 Dim _factura As New Factura()
 Private _datosreporte As dtFactura
 _factura.SetDataSource(_datosreporte)
 crwFactura.ReportSource = _factura
 crwFactura.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None

知道该怎么做吗?

Edit1:我检查了数据集,它不是空的,它包含我设置的路径

【问题讨论】:

    标签: vb.net winforms visual-studio-2010 crystal-reports crystal-reports-xi


    【解决方案1】:

    我已经找到了解决方案,任何人都有同样的问题。

    主要是把图片转成byte()

    然后像这样将 byte() 传递给行

    rowDatosFactura.Logo = ConvertImageFiletoBytes("F:\logo.jpg")
    

    图片转字节的方法是这样的

     Public Function ConvertImageFiletoBytes(ByVal ImageFilePath As String) As Byte()
            Dim _tempByte() As Byte = Nothing
            If String.IsNullOrEmpty(ImageFilePath) = True Then
                Throw New ArgumentNullException("Image File Name Cannot be Null or Empty", "ImageFilePath")
                Return Nothing
            End If
            Try
                Dim _fileInfo As New IO.FileInfo(ImageFilePath)
                Dim _NumBytes As Long = _fileInfo.Length
                Dim _FStream As New IO.FileStream(ImageFilePath, IO.FileMode.Open, IO.FileAccess.Read)
                Dim _BinaryReader As New IO.BinaryReader(_FStream)
                _tempByte = _BinaryReader.ReadBytes(Convert.ToInt32(_NumBytes))
                _fileInfo = Nothing
                _NumBytes = 0
                _FStream.Close()
                _FStream.Dispose()
                _BinaryReader.Close()
                Return _tempByte
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      相关资源
      最近更新 更多