繁体   English   中英

将图像添加到vb.net的Crystal报表中

[英]Add image to Crystal reports from vb.net

我有一个问题,我试图在水晶报告中以编程方式从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:我检查了数据集,它不是空的,它包含我设置的路径

我找到了解决方案,对于任何有相同问题的人。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM