【问题标题】:Dynamically adding multiple Images to a Crystal Report in vb.net (WinForms)在 vb.net (WinForms) 中动态地将多个图像添加到 Crystal Report
【发布时间】:2016-06-05 03:45:00
【问题描述】:

寻求帮助。

我之前使用 DataSet 和子表单将单个图像添加到 Crystal Report。

我认为我可以为多张图片复制这个。

我创建了包含 8 行名为 img1 -> img8 的数据集“图像”

我已经基于该数据集创建了一个子报表。

在我的 vb 代码中,我将 SubReport 的数据源设置如下:

初始调用:

    alertReport.OpenSubreport("AlertImages").SetDataSource(CreateImages(alertID))

创建图像:

Private Function CreateImages(ByVal alertID As Integer) As DataSet

        Dim data As New DataSet()

        data.Locale = Globalization.CultureInfo.InvariantCulture
        data.Tables.Add("Images")
        data.Tables(0).Columns.Add("img", System.Type.GetType("System.Byte[]"))

        Try

            Dim path As String = String.Format("{0}\{1}", HighAlertPath, alertID.ToString())

            If (Directory.Exists(path)) Then

                Dim cnt As Integer = 1

                For Each fi As FileInfo In New DirectoryInfo(path).GetFiles

                    If (cnt <= 8) Then

                        If (fi.Extension = ".jpg" Or fi.Extension = ".png" Or fi.Extension = ".bmp") Then

                            Dim row As DataRow = GetImageRow(data.Tables(0), fi.FullName)
                            data.Tables(0).Rows.Add(row)
                            cnt += 1

                        End If

                    End If
                Next

            End If

        Catch ex As Exception
        End Try

        Return data

    End Function

获取图像行:

Private Function GetImageRow(ByVal tbl As DataTable, ByVal fileName As String) As DataRow

    Using fs As New FileStream(fileName, FileMode.Open)
        Using br As New BinaryReader(fs)

            Dim row As DataRow = tbl.NewRow()
            row(0) = br.ReadBytes(CInt(br.BaseStream.Length))

            Return row

        End Using
    End Using

End Function

我可以确认文件位置确实包含图像,并且它们已添加到数据表中,但由于某种原因它们没有显示在子报告中。

我是否需要在将行添加到数据表时为其命名,因为我的子报表需要字段 img1 -> img8

【问题讨论】:

  • 谁能帮我解释一下这个?

标签: vb.net winforms crystal-reports


【解决方案1】:

我建议你在运行时创建一个PictureObject,在上面添加图片,然后添加到报表中。

看看这段代码:

Dim crxReport as CRAXDRT.Report
Dim objOLE As CRAXDRT.OLEObject
Dim objPic As StdPicture

'set all your CRAXDRT report and application objects, recordsets, etc

Set objPic = LoadPicture("myPath\myPic.bmp")

'here I am adding a picture object to the first section of the report
'now spacing here might get weird, you need to play with this and 
'figure out where this object will go

Set objOLE =   crxReport.Sections(1).AddPictureObject("myPath\myPic.bmp",0, 0)

'Set attributes of the image, we are dynamically creating it
'again you need to adjust accordingly

With objOLE
    .Height = objPic.Height * 500 / 1000
    .Width = objPic.Width * 500/ 1000
    .Left = (crxReport.Sections(1).Width) - objPic.Width
End With

Set objOLE = Nothing
Set objPic = Nothing

http://www.xtremevbtalk.com/database-and-reporting/109005-inserting-picture-objects-run-time-crystal-report.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    相关资源
    最近更新 更多