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 (6)   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


Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Blog_List
Module Border
Module Border Module Border
Module Border
  Subscribe
Module Border

RSS

Module Border Module Border
Module Border
  Diversions
Module Border

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



HOOK SHOT
This little basketball game was submitted as an entry to the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

INFO AND CODE



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) 2008 andy.beaulieu.com - Login