寻求一些帮助。
我以前使用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 - &gt; img8
答案 0 :(得分:0)
我建议您在运行时创建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