插入图像不会在水晶报表中显示图像 [英] Inserting image does not display image in crystal report
本文介绍了插入图像不会在水晶报表中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在数据库表格中给出的路径中显示水晶报表中的图像。我的代码运行良好,但报表中没有显示任何内容。我的代码。请帮助我找出问题。
I want to display image in crystal report from path given in database table.My code runs well but nothing is displayed in report.Below is my code.Please help me to find out the problem.
Dim Con As OdbcConnection = New OdbcConnection
Dim sql As String = "Select * from Image"
Con.ConnectionString = connstring
Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, Con)
da.Fill(ds, "Image")
ds.Tables("Image").Columns.Add("image_stream", Type.GetType("System.Byte[]"))
For index As Integer = 0 To ds.Tables("Image").Rows.Count - 1
If ds.Tables("Image").Rows(index)("image_path").ToString <> "" Then
Dim s As String = ds.Tables("Image").Rows(index)("image_path").ToString
If File.Exists(s) Then
LoadImage(ds.Tables("Image").Rows(index), "image_stream", s)
End If
End If
Next index
crDoc = New ImageReport
crDoc.SetDataSource(ds.Tables("Image"))
rptDoc.ReportSource = crDoc
Private Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
Try
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
objDataRow(strImageField) = Image
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
推荐答案
在数据单元格中填充图像表
并确保我成功读取年龄并插入单元格
fill image in cell of data table
and make sure image is successfully read and inserted in to cell
For index As Integer = 0 To ds.Tables("Image").Rows.Count - 1
If ds.Tables("Image").Rows(index)("image_path").ToString <> "" Then
Dim s As String = ds.Tables("Image").Rows(index)("image_path").ToString
If File.Exists(s) Then
Drawing.Bitmap img = new Drawing.Bitmap(ds.Tables("Image").Rows(index)("image_path").ToString); //Replace string with your OpenFileDialog path.
MemoryStream ms = new MemoryStream();
Image returnImage = Image.FromStream(ms);
System.Drawing.Image imageIn = new System.Drawing.Image();
imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
ds.Tables("Image").Rows(index)("image_stream") = ms.ToArray();
End If
End If
Next index
快乐编码!
:)
Happy Coding!
:)
这篇关于插入图像不会在水晶报表中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文