Importing Dynamic Images to the Crystal Report without Database Overhead using Visual Studio 2005
page 1 of 3
Published: 10 Jan 2007
Abstract
In this article Pradeep demonstrates how to import dynamic images to the Crystal Report without any database overhead with the help of code samples.
by Pradeep Shukla
Feedback
Average Rating: 
Views (Total / Last 10 Days): 86385/ 60
Article Contents:

Introduction

When it comes to import a dynamic image to the Crystal report, one would like to follow the traditional approach of storing the image in the database and then pull it to the report.

But there are some overheads associated with using a database to store the binary/Images file. The primary being the database connections are more expensive and pulling your images out from the database may be time taking.

In this Article I would like to demonstrate how to achieve this without the intervation of the database.

To start with let say we have a dynamic chart that gets displayed in the aspx page and we need to display that chart in the report. Here we have another option i.e we can use the inbuilt chart feature of the Crystal Report. But it will not always be feasible if the chart is fully dynamic in nature. In one of my project I did face this issue. I simply can not have all the conditions for all the possible cases. So the simple workaround for me was just to save my image in the server at runtime and then import that to the Crystal Report and it worked fine.


View Entire Article

User Comments

Title: bytearr   
Name: murali
Date: 2013-01-25 7:23:59 AM
Comment:
can u send full source...........
Title: Thanks Man   
Name: MSVercetti
Date: 2012-09-10 1:09:32 PM
Comment:
Thanks a lot men. I have spent a lot of my time finding a solution for that. In my case, i couldn´t import an image for a factur in a Crystal Report, and you fix my problem like a "Boss". I know that this post is old, but is so excelent. Thanks again.
MSVercetti - From Cuernavaca Morelos - Mexico
Title: You are the man!   
Name: Hichamito
Date: 2012-06-25 5:17:40 PM
Comment:
Many hours of googling, finaly i find what i want in this article, thanks man!
Title: Image not display   
Name: Chetan
Date: 2011-12-12 1:44:49 AM
Comment:
Hiii thanks for this article but i cant see image on crystal report...
it is not showing any image and no error msg.
Pls help me if possible on my id
chetan2010joshi@gmail.com
Title: Step Link doesn't work   
Name: ASD
Date: 2011-10-24 5:51:29 AM
Comment:
When i click the step link. There is nothing to show. Nothing describes for this link(page 2).
Title: Everything OK   
Name: Paco
Date: 2011-04-29 5:35:25 AM
Comment:
Thank you for this article. It was very very useful for me. Everything worked fine with VS2008.
Title: Image is not showing   
Name: Ravi
Date: 2011-03-25 1:22:23 AM
Comment:
I have done exactly as shwon in the article and executed with no errors, but no image is shwon, can any body send me a sample working project / code. I am using VB.Net 2005 Windows Application. Plesae sent me to my personal email id
lakkimb4u@gmail.com
Title: byteArr is pointing to what?   
Name: maddy
Date: 2011-03-12 8:30:45 AM
Comment:
Can Anyone Share the correct working code for this line:

drawingImage = System.Drawing.Image.FromStream(New System.IO.MemoryStream(byteArr));

What is (byteArr) pointing to?

Please help.

Maddy
Title: Display Image from Network Location   
Name: Parm
Date: 2011-02-04 12:22:06 PM
Comment:
Hi I am using Crystal 7 and have a requirement to display product images in the report following the product specification.

Does anyone know who this can be achieved in this version?

Many Thanks
Parm
Title: how to display image dynamically on the report   
Name: Vishal Mohan
Date: 2011-01-26 7:24:21 AM
Comment:
Hi,
I want to show the images in Crystal report dynamically,I have store the full path of image in database,now I have to show the image correspond to that path in crystal report each row. Plz can you describe how can i do this my personal id is i.vish333@gmail.com
Thanking you
please help me .........
Title: help me please I don't know what do with that? ByteArr How to use it?   
Name: binu
Date: 2010-12-18 5:43:05 AM
Comment:
help me
Title: crystal reports 8.5 dynamic image help   
Name: Sabir Husain
Date: 2010-10-07 4:00:26 AM
Comment:
Hi,
I want to show the images in Crystal report dynamically,I have store the full path of image in database,now I have to show the image correspond to that path in crystal report 8.5 with each row. Plz can you describe how can i do this my personal id is husain_sabir@rediffmail.com
Thanking you
Title: query   
Name: Hardik Patadia
Date: 2010-09-06 10:18:59 AM
Comment:
i m having records of students in database and i want the photos of those students corresponding to the record in the database... is it possible by the method suggested by you
if possible reply me on hardik_patadia@yahoo.co.in
Title: Sample project   
Name: Anil
Date: 2010-08-23 11:43:21 PM
Comment:
can any body please send me sample project to display images on crystal report My Images are stored on harddisk have created dataset but its asking logon information for dataset
what to give ???
please send me sample working code karwankar@e-gecaect.com
Title: How to show images in CR 2008 from a URL   
Name: Abhay D
Date: 2010-08-10 6:00:52 AM
Comment:
I have added a picture to report. Then on picture location, I have given the http address of picure, but it always show the local image. Could anyone please help me on this.
Thanks in advance
Abhay
Title: Size of images   
Name: Pierre Villain
Date: 2010-06-23 9:22:08 AM
Comment:
Nice job and thank you for all advices.
But, I have one more question:
We store images in our database. For example, one image of "table" for the product "table".
We would like to have a report which could get images in terms of our product in crystal report.
If we select the product "Chair", we would like to show the image "Chair" linked to the product.
The matter is size of images is up to the product.
Does crystal report resize the image each time we will load the report?
We don't want to have different sizes for our image.
For all products we would like the same size of image into our report.

Thank you for your help.
Best Regards,
Title: byteArr   
Name: Matej Ċ kerjanc
Date: 2010-06-21 9:13:34 AM
Comment:
ok consider this code:

private byte[] downloadedData;
...
code to fill this downloadedData;
for instance from memorystream.ToArray();
...

byte[] imageData = downloadedData;
MemoryStream stream = new MemoryStream(imageData);
System.Drawing.Image Img1 = System.Drawing.Image.FromStream(stream);

I hope it clarifies this further...
________________________________________________________
on the other hand i got some other problem
On the site i use this (my report site) gets info : "The report you requested requires further information."

It seems this dataset requires further info, but why i'm not connecting to a base..i'll be real grateful for explanation;)
Title: Use CSS   
Name: John Aneston
Date: 2010-06-19 7:42:10 AM
Comment:
Its actually pretty simple to import(or just call reference) images. I got this idea while implementing CSS to a report viewer page.

step1:
Use this in your report displaying aspx page
>html<
>head<
>style<
.classname
{
background:url(images/xyz.jpg) no-repeat left top; }
>style<
>/head<
>body<
>crp:crystalreportviewer load<
>/body<
>/html<

step2:
Insert a Textbox object in your .rpt file

step3:
Right click textbox object and select Format Object, under "CSS Class Name" give the classname mentioned in your aspx page.

step4:(optional)
If you are to use dynamic images, repeat step1 for all images and go to step3. Then create formulas to provide the respective classnames dynamically.

Its as simple as that.
Title: byteArr   
Name: JV
Date: 2010-06-10 3:41:40 AM
Comment:
im also having problem w/ this code.

do we need to import something?

drawingImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream (byteArr));
Title: byteArr   
Name: Matej Ċ kerjanc
Date: 2010-05-26 7:37:49 AM
Comment:
regarding byteArr....


i did similar



DownloadData(url2);
byte[] imageData2 = downloadedData;
MemoryStream stream2 = new MemoryStream(imageData2);
System.Drawing.Image Img2 = System.Drawing.Image.FromStream(stream2);
stream2.Close();


DownloadData accepts url and sets local variable downloadedData (the image from url in byte array)
Title: Small change   
Name: Robin Thomas
Date: 2010-03-18 4:02:57 AM
Comment:
Thanx for this wonerful post.
very small mistake.
row[0] = br.ReadBytes(br.BaseStream.Length);
should be changed to

row[0] = br.ReadBytes((int)br.BaseStream.Length);
Title: image path   
Name: iqbal ahmad
Date: 2010-01-22 5:32:40 AM
Comment:
I using cr11 i want how to creat imagepath from image folder
Title: byteArr   
Name: kumar
Date: 2009-12-16 5:18:09 AM
Comment:
what this byteArr do? Could u plz give me an idea.
Title: Whre is the answer to that??   
Name: YLO
Date: 2009-12-15 10:03:26 AM
Comment:
but one should always never assume that the user is going to know what to do with "byteArr" or what it represents. Please show all code relevant to the post.
Title: Got It   
Name: Paul
Date: 2009-11-26 8:20:37 PM
Comment:
this article is greate, i got my image to the report
thanks a lot.
Title: byteArr   
Name: Jeremy
Date: 2009-10-23 12:15:49 PM
Comment:
Good queation, William. These articles are great, but one should always never assume that the user is going to know what to do with "byteArr" or what it represents. Please show all code relevant to the post.
Title: byteArr???   
Name: William
Date: 2009-10-16 5:47:11 PM
Comment:
help me please I don't know what do with that?
ByteArr
How to use it?
Title: Mr.   
Name: Sandeep RAI
Date: 2009-09-04 3:48:37 AM
Comment:
Thank you very much for this article, It could be listed on top of google search. I have been searching for this solution quite a long...
thanks once again
Title: an issue   
Name: Kishor
Date: 2009-09-02 10:12:16 AM
Comment:
I m new. pls tell me.
drawingImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream (byteArr));

what is byteArr?
Title: THANKS   
Name: Ariel
Date: 2009-08-26 4:38:01 PM
Comment:
Great Article!
Title: Thanks!!!!   
Name: Raj
Date: 2009-08-20 3:32:29 PM
Comment:
Great article...Thanks you very much!!!!
Title: Email   
Name: Faisal Rehman
Date: 2009-07-20 11:32:42 AM
Comment:
well glad to see the example and the comments tht every1's prb is solved now. but my app is still not working, not showing any pic :( can any 1 email me the working project :( ?? my email id is janu.bravo@gmail.com
Title: Author   
Name: Pradeep Shukla
Date: 2009-06-22 7:08:20 AM
Comment:
Thank you friends for liking my articles so much..It gives me a lots of inspiration.
Title: Mr.   
Name: Zaib Khan
Date: 2009-06-22 12:50:27 AM
Comment:
Thank you very much for this article, It could be listed on top of google search. I have been searching for this solution quite a long...
thanks once again
Title: web Developer   
Name: Ahmed Ibrahim
Date: 2009-06-14 5:07:42 AM
Comment:
I very Like This Article
Thanks Alot For your Effort
Title: Thanks!   
Name: Ray
Date: 2009-04-08 12:08:58 PM
Comment:
This works perfect, thanks you. Now I just need to hunt around to find out how to keep the image perspective, and why the images look aweful. They seem to be getting dithered when I export a PDF in VB/net! Crystal report...gotta hate it.
Title: Dynamic Size for Dynamic Images?   
Name: Selma
Date: 2009-03-13 9:44:18 AM
Comment:
thanks a lot for this article, it is very useful.
I have another Problem. Is it possible to set size of this Dynamic Image also dynamicaly?
Title: Comment   
Name: Tony
Date: 2009-02-19 8:15:26 AM
Comment:
thanks a million man - I tried all sorts of things before i landed up on your life saving article. - Thanks!
Title: Dynamic Images in Crystal Report   
Name: Rejin kumar
Date: 2009-02-13 4:24:06 AM
Comment:
Thank you very much for this article, It could be listed on top of google search. I have been searching for this solution quite a long...
thanks once again
Title: Print Images on Crystal Report 7 using VB6   
Name: Alok Seth
Date: 2008-12-29 5:30:14 AM
Comment:
Hello Everyone. I want to print Images that are stored in my PC folder and store complete path in my Database. Now, I want to Print these file with Picture in Crystal Report 7. So, please help me.. my mail ID is alok.seth@yahoo.co.in
Title: Please help   
Name: Sanjivani
Date: 2008-10-21 9:09:26 AM
Comment:
Thank you very much for this article. It s very informative. Bt i m getting one problem. i am nt able to see image. Instead of that binary data is displayed. Can u please guide me wat might be the problem?
Title: Eng.   
Name: Mohammed El-Said
Date: 2008-10-18 8:59:11 PM
Comment:
Excellent Article
Thanks very much
Title: Display Dynamic Image In Crystal Report 10.0   
Name: ketan
Date: 2008-09-14 11:29:15 AM
Comment:
I have Archive that One In My One IDBadge Application

See this :- http://dotnet-magic.blogspot.com/2008/09/crystalreport-100-dynamic-image-display.html
Title: little more   
Name: Naveed Anjum
Date: 2008-09-12 7:28:51 AM
Comment:
hi Pradeep Shukla,
very good article u wrote here for us
thanks
actually i m using VS-2005 .net, and crystal report.
i don't have image field in my DataTable,
i added ImageColumn in DataTable at runtime ..
But i don't have image field in "Object Explorer"
How can I add image field to the Crystal Report on Design time.
and How will it Bind with Data in Dataset..
Title: The report you requested requires further information.   
Name: Ahmad
Date: 2008-08-13 5:37:18 AM
Comment:
i have problem with crystal report i didn't finf any answer of my question the title appear to me when i run the report now am using dataset created from solution explorer and i called it from report from ado.net folder so i don't know how solve this problem
Title: Image size problem   
Name: Sachin Devre
Date: 2008-07-15 8:09:45 AM
Comment:
Hi,

I am able to display images on crystal report run time. Also to maintained aspect ratio, I have set property can grow.
But this cause a problem, it shrinks the images while displaying.
Can it be resolved?
Title: I have a poblem   
Name: by Luca
Date: 2008-07-09 8:20:06 AM
Comment:
Hi, I'm Luca..i did all these but in report no images came..I import in crystal report the datatable, but crystal see the object like a number, not like a image..I don't know..Can you help me please? It's a very difficult problem for me..thanks..bye, Luca
Title: Plz Help   
Name: Sam
Date: 2008-06-13 5:09:21 AM
Comment:
No image is coming. can u plz add the source code for download
Title: Plz help!   
Name: Reshma
Date: 2008-06-05 2:52:06 AM
Comment:
Everything works fine,But finally when i set the datasource of the crystal report with the data table it shows the following exception.
"Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))".
Plz do help .
Title: Image   
Name: nitu
Date: 2008-05-12 4:49:04 AM
Comment:
I am developing a application of printing the Icard. so i have a problem in the crystal report.that how to import one or more images dynamically on crystal report in vb.net 2005. if image is stored in a particular image folder and nothing stored in the database.
Title: How to retriew image from database   
Name: Sonali bahndare
Date: 2008-05-12 4:35:40 AM
Comment:
hi, i have one question. I want to store an image in database in binnary format. & display that image in crystal report . I you tell me how it is work in vb 6.0
Title: dynamic one or more image in crystal report help   
Name: Ramesh
Date: 2008-05-07 7:43:08 AM
Comment:
I am developing a application of printing the Icard. so i have a problem in the crystal report.that how to import one or more images dynamically on crystal report in vb.net 2005. if image is stored in a particular image folder and nothing stored in the database.
Title: crystal reports dynamic image help   
Name: Ramesh Jangir
Date: 2008-05-07 7:32:19 AM
Comment:
how to show a image dynamically on crystal report in vb.net 2005. if image is stored in a folder and nothing stored in the database.
Title: works great   
Name: Raj
Date: 2008-01-21 7:44:53 PM
Comment:
Thanks man. It works great.

One should be careful about setting the img's datatype in the datatable to byte[]. You cannot set it directly to byte[] in the properties, however you change it in the source code.
ex: data.Columns.Add("img", typeof(Byte[]));
Don't forget to resynchronize the data base in crystal if you are already have the dataset in the database of crystal.

Hope this would be helpful for the other friends how are struggling.

More info look at:

http://www.msdner.net/dev-archive/95/2-7-955602.shtm
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=233496&SiteID=1

happy coding
Raj
Title: Show images on crystal reports   
Name: Raveens
Date: 2008-01-18 1:33:31 AM
Comment:
Hi, I would like to import the images which are there on the database. The image is stored in the database in bytearray (bytea()) format. I am able to get the content in the column. But how to get the image directly along with other column data.

Thnx in advance
Title: Not ab;e to set the data type of image to System.Byte[]   
Name: Binu
Date: 2008-01-16 1:06:07 AM
Comment:
Hi I tried this method but the data type System.Byte[] is not listed in the list of available datatypes. I'm working in VS2005
Title: How to declare byteArr with initial value   
Name: Mahinder Lal
Date: 2008-01-07 2:36:13 PM
Comment:
Can you please also explain how to declare byteArr with initial value to avoid runtime null error? I tried declaring it as Byte(), but get null buffer error at runtime.

Thanks
Title: ho to show a dynamic image on crystal report in vb.net 2003 path is stored in data base and image in image folder in root directory   
Name: manmohan
Date: 2007-12-19 7:33:56 AM
Comment:
how to show a image dynamically on crystal report in vb.net 2003 path is stored in data base and image is in image folder in root directory. Thanks
Title: Good Job   
Name: Friend
Date: 2007-10-24 7:13:08 AM
Comment:
Works prefect
Title: crystal reports dynamic image help   
Name: ankit
Date: 2007-10-23 5:54:49 AM
Comment:
Hi,
I want to show the images in Crystal report dynamically,I have store the full path of image in database e.g. (http://0.0.0.0/someimages.jpg),now I have to show the image correspond to that path in crystal report.PLz can you describe how can i do this my personal id is ankit.panchal@zmail.ril.com
Title: image not shown   
Name: laby
Date: 2007-10-12 7:26:03 AM
Comment:
i am using windows appln help help me
Title: image not shown   
Name: laby
Date: 2007-10-12 7:24:48 AM
Comment:
i did all these but in report no images came but help me out
Title: Logon to the database??? Server = dataset????   
Name: Sladjana
Date: 2007-08-22 9:29:32 AM
Comment:
there is just one problem, Crystal Reprots demands to Log On to the database, and the name of the dataset is in the server field. I tried to set database logon to false, but it doesn't work. How to avoid logon or how to set the logon?????
Thanks
Title: Q   
Name: Ethan
Date: 2007-08-16 2:07:13 PM
Comment:
can you please add a full VS proyect to download??
Title: works very well but handle with care   
Name: vishal giri
Date: 2007-08-07 10:27:34 AM
Comment:
datatype to dataset column check System.Byte[] that square brackets are very imp wasted my 5 hours
Title: feedback   
Name: Rajib
Date: 2007-07-09 8:34:27 AM
Comment:
i just took it let's hope it will work.But surely i will get a idea from this article
Title: Please Send me Crystal report help   
Name: Pravin B pandit
Date: 2007-06-30 9:03:14 AM
Comment:
Hi,
I want to show the images in Crystal report dynamically,I have store the full path of image in database,now I have to show the image correspond to that path in crystal report.PLz can you describe how can i do this my personal id is pravinbpandit@gmail.com
Title: More Detail On this   
Name: Rohit
Date: 2007-06-18 8:18:08 AM
Comment:
Hi,
I want to show the images in Crystal report dynamically,I have store the full path of image in database,now I have to show the image correspond to that path in crystal report with each row.PLz can you describe how can i do this my personal id is rohit.vyas@suviinfo.com
Title: finally   
Name: Guillermo Avila
Date: 2007-02-27 9:04:14 AM
Comment:
Thanx, it works perfect. No need to buy Crystal Reports XXXXXIIIIIII the revenge 2.!!
Title: thanks   
Name: guest
Date: 2007-02-10 8:40:13 AM
Comment:
this is just what i needed..thanx
Title: Mr.   
Name: Murat
Date: 2007-02-04 4:50:29 PM
Comment:
i did all these but in report no images came :(

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 6:19:42 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search