 |
|
|
|
Dynamic Images in Crystal Reports .NET
|
|
|
 |
|
Location: Blogs Andy's Blog |
|
| Posted by: host |
1/27/2005 8:10 PM |
You would think this is a simple task: let's say you have a Crystal Report and you want to dynamically change an image in the report by loading an image from disk. Well, as it turns out, this functionality is not available in CR for .NET!
But here is a work-around; Crystal for .NET does support displaying images from a DB. And it does support accepting a disconnected ADO DataSet as a data source. So you can trick Crystal into thinking it loaded an image from disk and presto, you have dynamic images from disk. Here's the process:
(1) Create an XSD file (you'll use this as your report data source in step 2) with a binary column definition like so:
<xs:element name="AnImage" type="xs:base64Binary" minOccurs="0" />
(2) Create your Crystal Report and use an ADO.NET (XML) DataSource as your Crystal Report Data Source.
(3) Fill your DataSet, and then set the binary “image” column to an image file from disk using a MemoryStream like so:
Dim oLogo As System.Drawing.Image Dim msX As New MemoryStream Dim dsReportSource As New DataSet ' TODO: Fill your DataSet, dsReportSource, with your Report Data
' Load your image from disk oLogo = oLogo.FromFile("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Blue hills.jpg") ' Save the image data to a Memory Stream oLogo.Save(msX, System.Drawing.Imaging.ImageFormat.Bmp) ' Set the binary "image" column in your DataSet to the image data (note dsReportSource is a typed DS here) dsReportSource.TestImage(0).AnImage = msX.GetBuffer
(4) Load your Crystal Report and assign the Data Source as usual:
Dim oRpt As New ReportDocument oRpt.Load("CrystalReport1.rpt") oRpt.SetDataSource(DsTestImage1) CrystalReportViewer1.ReportSource = oRpt |
|
| Permalink |
Trackback |
Comments (9)
Add Comment
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
7/30/2007 6:23 AM
|
Thanks! It was very helpful for me.
Regards, Marcin
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
8/14/2007 7:23 AM
|
Thanks ya,
it is very useful and simple
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
10/10/2007 2:52 AM
|
sir andy..
im stupid and im very new in asp.net...please guide me step by step here...
tnx, jb
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
10/28/2007 3:32 PM
|
|
It´s very very useful for me, thanks!!
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
11/7/2007 5:46 PM
|
Great stuff, works like a charm and the explanation is simple
thanks tj
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
12/10/2007 4:01 PM
|
|
Great solution, it is ver useful to solve my problem
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
5/20/2009 9:50 AM
|
No Luck.. my report is still showing the blank image "X Image".
I was trying to display my report logo at report header by using XSD file. I have added a table and an element of type="xs:base64Binary" in xsd and "drag and drop" the field on my rpt file.
Any idea whats wrong!!
|
|
|
Re: Dynamic Images in Crystal Reports .NET
|
By Anonymous on
8/27/2010 1:18 AM
|
WARNING: If your image is too big to fit into a section it simply will not appear. Took me a long time to figure this out.
|
|
|
Dynamic Images in Crystal Reports .NET through Database Path alone.
|
By Anonymous on
10/7/2011 7:33 AM
|
|
Dynamic Images in Crystal Reports .NET through Database Path alone.
|
|
|
|
 |
|
 |
|
|