SpriteHand
Module Border
  Dynamic Images in Crystal Reports .NET
Module Border
Location: BlogsAndy'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.


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border

TALKING RAGDOLL
This Windows Phone 7 App was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



DROPPYPOP
This Windows Phone 7 game was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine.
DEMO

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight 2, the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2013 andy.beaulieu.com - Login