Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Printing Dynamic Images in Crystal Reports
Message
General information
Forum:
ASP.NET
Category:
Reporting
Title:
Printing Dynamic Images in Crystal Reports
Miscellaneous
Thread ID:
00906230
Message ID:
00906230
Views:
75
Ahmad (and anyone else)...

This is in response to your question about dynamically setting images in a report using Crystal. I wanted to start a new thread.

Apparently, this has been either easy or not-so-easy, depending on which version of Crystal one is using!

In the version of Crystal that came with VB6, there was a FORMAT event for the section object. The event fired every time a section was about to be printed, so one could hook into that event. This would permit loading a new image for every report row. Specifically, when you hook into the format event, you declare an OLEOBJECT variable, and set it to the image object of the section. Then call SETOLELOCATION and pass it the name of the new image.

(And by the way, if you want to display a JPG, I've read that you'll need a JPG OLE Server application on the computer. Apparently, CR won't display JPG images natively).

The FORMAT event was removed from the the version of Crystal that came with .NET. And then it was added back into the RDC that came with more recent versions of Crystal.

So for CR.NET, you have two options:

1) If you're using a back-end database that supports images (e.g. blob field in SQL Server or Access), you can store the images in a blob field, and then add the field on the report in the same way you'd use any other field.

2) If #1 isn't an option, you can try the following:

a) For the datatable that's associated with the rows where the image would be displayed, add a new column using the data type of BYTE(). This column is what we'll use to store the image

b) save this new table structure as an XML file

c) Create the new report, using the XML schema file. Place the image field on the report where you want to display it.

d) At runtime, when you're generating the report, you'll need to get the file path of the image and load the image into memory and save it to the new column of the row.

e) run the report the way you normally would

For the actual step that loads the image into the column, you have to do something like this (I think you were using VB.NET). Here's a generic function to load an image

LoadPicture(NewRowToBeAdded, "c:\myimagepath\","Employee1Image.bmp")

LoadPicture(NewRowToBeAdded, "c:\myimagepath\","Employee2Image.bmp")


Public Shared Sub LoadPicture(ByVal MyRow As System.data.DatRow, ByVal MyFilePath As String, ByVal MyImageField As String)

Dim fstream As New System.IO.FileStream(MyFilePath, IO.FileMode.Open,
System.IO.FileAccess.Read)
Dim MyImage(fstream.Length) As Byte
fstream.Read(MyImage,0,fstream.Length)
fstream.Close()
MyRow.Item(MyImageField) = MyImage
End Sub

Not to sound like a salesman, but this approach came from the book I mentioned before, Crystal Reports .NET Programming by Brian Bischof. This five-star book has countless examples for things like this.

Hope this helps!
Kevin
Next
Reply
Map
View

Click here to load this message in the networking platform