水晶报表中的图像 [英] images in crystal report

查看:55
本文介绍了水晶报表中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用vb.net代码将图像从本地磁盘传递到Crystal报表,我已经完成了将一个图像从本地驱动器传递到Crystal报表的操作,但是问题是我想从同一驱动器传递很多图像,我在下面使用编码以传递图像..

hi all,
i am passing images from my local disk to crystal report using vb.net code, i have completed for passing one images from my local drive to crystal report, but the issue is i want to pass many images from same drive, i am using below coding for passing images..

Dim dt As New DataTable
      ' object of data row
      Dim drow As DataRow
      ' add the column in table to store the image of Byte array type
      dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"))
      drow = dt.NewRow
      ' define the filestream object to read the image
      Dim fs As FileStream
      ' define te binary reader to read the bytes of image
      Dim br As BinaryReader
      ' check the existance of image
      If File.Exists(AppDomain.CurrentDomain.BaseDirectory & "10157.Jpg") Then
          ' open image in file stream
          fs = New FileStream(AppDomain.CurrentDomain.BaseDirectory & "10157.Jpg", FileMode.Open)
      Else ' if phot does not exist show the nophoto.jpg file
          fs = New FileStream(AppDomain.CurrentDomain.BaseDirectory & "FLYWELL.jpg", FileMode.Open)
      End If
      ' initialise the binary reader from file streamobject
      br = New BinaryReader(fs)
      ' define the byte array of filelength
      Dim imgbyte(fs.Length) As Byte
      ' read the bytes from the binary reader
      imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)))
      drow(0) = imgbyte       ' add the image in bytearray
      dt.Rows.Add(drow)       ' add row into the datatable
      br.Close()              ' close the binary reader
      fs.Close()              ' close the file stream
      Dim rptobj As New CrystalReport1    ' object of crystal report
      rptobj.SetDataSource(dt)
      ' set the datasource of crystalreport object
      CrystalReportViewer1.ReportSource = rptobj  'set the report source

推荐答案

您已经拥有了所需的一切,只需重组即可.
将此代码放入传递文件名和数据表作为参数的方法中.然后为要添加到报告中的每个文件调用它.将这些语句移动为仅在调用方法后才被调用一次:
You''ve already got everything you need, you just need to reorganize it.
Put this code into a method that passes in the the file names, and the data table as parameters. Then call it for each file you want to add to the report. Move these statements to be called only once after you''ve called your method:
Dim rptobj As New CrystalReport1
rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj




--------------------------------------
好吧,我会再向您推向正确的方向.创建这样的方法:




--------------------------------------
Okay, I''ll give you one more push in the right direction. Create a method like this:

Private Sub AddImage(ByRef dt As DataTable, ByVal strFileName As String)
'Put your code in here, minus the three statements I mention above
'And change "10157.Jpg" to strFileName
End Sub



现在,在您以前拥有代码的地方,输入如下内容:



Now where you used to have your code, put something like this:

Dim dt as New DataTable
AddImage(dt, "10157.Jpg")
AddImage(dt, "secondImage.jpg")
AddImage(dt, "thirdImage.jpg")

'Now those last three lines
Dim rptobj As New CrystalReport1
rptobj.SetDataSource(dt)
CrystalReportViewer1.ReportSource = rptobj



您必须找出我错过的所有小错误,但这应该可以帮助您入门.



You''ll have to work out any little bugs I''ve missed, but this should get you started.


这篇关于水晶报表中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆