从vb.net向Crystal报表添加图像

从vb.net向Crystal报表添加图像,vb.net,winforms,visual-studio-2010,crystal-reports,crystal-reports-xi,Vb.net,Winforms,Visual Studio 2010,Crystal Reports,Crystal Reports Xi,我有一个问题,我试图在crystal reports中以编程方式替换vb.net中的图像 我就是这么做的: Dim facturacion As New dtFactura() rowDatosFactura.Logo = "F:\imgtest.png" facturacion.DatosFactura.AddDatosFacturaRow(rowDatosFactura) 我将图像路径设置为数据集 然后在te数据集中添加字符串以替换crystal reports中的图像 在cyrstal

我有一个问题,我试图在crystal reports中以编程方式替换vb.net中的图像

我就是这么做的:

Dim facturacion As New dtFactura()
rowDatosFactura.Logo = "F:\imgtest.png"
facturacion.DatosFactura.AddDatosFacturaRow(rowDatosFactura)
我将图像路径设置为数据集

然后在te数据集中添加字符串以替换crystal reports中的图像

在cyrstal reports下,我添加了一个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:我已经检查了数据集,它不是空的,它包含我设置的路径

我已经找到了解决方案,适用于任何有相同问题的人

主要是将图像转换为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