Click here to Skip to main content
12,828,403 members (45,879 online)
Click here to Skip to main content
Add your own
alternative version


73 bookmarked
Posted 30 Oct 2007

Image in Crystal Reports

, 30 Oct 2007
Rate this:
Please Sign up or sign in to vote.
This is sample small project to display image in crystal report
Screenshot - ImgInReport.gif


This article will display the image in crystal report viewrBackground

Using the code

Simply open the source code in 2003.

    try { 
        // here i have define a simple datatable inwhich image will recide 
        DataTable dt = new DataTable(); 
        // object of data row 
        DataRow drow; 
        // add the column in table to store the image of Byte array type 
        dt.Columns.Add("Image", System.Type.GetType("System.Byte[]")); 
        drow = dt.NewRow; 
        // define the filestream object to read the image 
        FileStream fs; 
        // define te binary reader to read the bytes of image 
        BinaryReader br; 
        // check the existance of image 
        if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg")) { 
            // open image in file stream 
            fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg", FileMode.Open); 
        else { 
            // if phot does not exist show the nophoto.jpg file 
            fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open); 
        // initialise the binary reader from file streamobject 
        br = new BinaryReader(fs); 
        // define the byte array of filelength 
        byte[] imgbyte = new byte[fs.Length + 1]; 
        // read the bytes from the binary reader 
        imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length))); 
        drow(0) = imgbyte; 
        // add the image in bytearray 
        // add row into the datatable 
        // close the binary reader 
        // close the file stream 
        CrystalReport1 rptobj = new CrystalReport1(); 
        // object of crystal report 
        // set the datasource of crystalreport object 
        CrystalReportViewer1.ReportSource = rptobj; 
        //set the report source 
    catch (Exception ex) { 
        // error handling 
        Interaction.MsgBox("Missing 10157.jpg or nophoto.jpg in application folder"); 
// run the application to view image in report 

Remember if you are using c# the paste the above code in button click event

Points of Interest

In this article you will be also able to convert the image into byte array


In this project after clicking the button the action are performed you are free to modify as per your requirement
Feel free for any querrrrrries.

enjoy .net


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

TangoCharli (Anant Tiwari)
Software Developer (Senior) Avenues Technologies Pvt Ltd
India India
MCTS Microsoft Certified Technology Specialist
Computer Engineer

You may also be interested in...

Comments and Discussions

QuestionIt is possible to choose the location where the image will be added no rpt ? Pin
bydario1-Jun-16 9:09
memberbydario1-Jun-16 9:09 
QuestionAdding image from path specified Pin
Member 1207720221-Oct-15 11:42
memberMember 1207720221-Oct-15 11:42 
Questionview jpg image pdf using crystal report Pin
Member 108569972-Aug-15 18:49
memberMember 108569972-Aug-15 18:49 
QuestionNow working Pin
heemanshu bhalla25-Oct-13 5:17
memberheemanshu bhalla25-Oct-13 5:17 
QuestionNot working Pin
heemanshu bhalla25-Oct-13 1:23
memberheemanshu bhalla25-Oct-13 1:23 
GeneralMy vote of 5 Pin
Member 937103828-Jun-13 1:13
memberMember 937103828-Jun-13 1:13 
GeneralMy vote of 5 Pin
supriya chaladi28-Jan-13 23:12
membersupriya chaladi28-Jan-13 23:12 
GeneralThnk u Pin
kiransolkar24-Dec-12 22:05
memberkiransolkar24-Dec-12 22:05 
QuestionBlob Field Pin
Raghavendra Rao 55815-Nov-12 2:01
memberRaghavendra Rao 55815-Nov-12 2:01 
Questiondatabase expert query Pin
Nikhil S Soni23-Oct-12 1:40
memberNikhil S Soni23-Oct-12 1:40 
AnswerRe: database expert query Pin
kiransolkar24-Dec-12 21:41
memberkiransolkar24-Dec-12 21:41 
GeneralMy vote of 5 Pin
manoj kumar choubey23-Feb-12 20:13
membermanoj kumar choubey23-Feb-12 20:13 
Generalwant image to be shown on special point of Report Pin
edinazem2-May-11 22:34
memberedinazem2-May-11 22:34 
GeneralMy vote of 5 Pin
sohebrapati19-Mar-11 2:31
groupsohebrapati19-Mar-11 2:31 
AnswerSimple Solution - BlobField - How answered Pin
IndomitablePhoenix10-Jan-11 13:02
memberIndomitablePhoenix10-Jan-11 13:02 
Generalpdf too large Pin
yi24-Oct-10 0:44
memberyi24-Oct-10 0:44 
AnswerRe: pdf too large [modified] Pin
IndomitablePhoenix11-Jan-11 8:38
memberIndomitablePhoenix11-Jan-11 8:38 
Have you tried to set the following attributes for the IBlobField Confused | :confused: :
{right-click the IBlobField & select "Format Object"}

1) "Can Grow" should be deselected if you want the size to be finite & not dependant on the size of the image
(if it is selected, the crystal report will adjust the document to be enlarged according to the actual image size Shucks | :-\ )
-------------- a) you could also add conditions for the "Can Grow" property (click on the button with a pen & "X" sign on it) -------------- using the "Formula Workshop - Format Formula Editor - Can Grow" tool to specify those conditions

2) "Close border on page break" should be selected

3) "Keep object together" should be selected

4) In the "Picture" tab, you can set the "Scaling", or the "Crop From" or the "Size" attributes to manipulate your image display in the report

5) you can add a special section for the image by adding subsections in the report (right click on an empty area in the report, Insert -> Section) [OR] (right-click on a section header, "Selection Expert" or "Insert section below") & then control/set the section properties {you can set "Suppress blank section" for the particular section}

Also, attempt other document type conversion (other than PDF : .doc, .rtf, .xls) & see if the same problem occurs. You can attempt to extract to formats which aren't too large & then converting those to pdf either by using macros or plug-ins or active-X components....depends on your application.
-------------Tip: When converting the document it is better using the Crystal Report Viewer; but you can also do
-------------this programmatically to be done @ run-time.

Often the case is that some design elements (from the toolbox) being not properly set cause layout inconsistencies (i had a problem with showing bi-directional text when converting the crystal report into pdf Sigh | :sigh: - the non-english text would be at one side & the other english text on the other with space between them in one line to mimic a justified layout but OMG | :OMG: one side wouldn't appear when converted Dead | X| ); these could be fixed by separating elements that are of different types ( D'Oh! | :doh: in this case creating separate textboxes for each type of text D'Oh! | :doh: ) or other work-arounds.

For other possible solutions on how to create a blobfield for the image - check out this link: Big Grin | :-D

Roll eyes | :rolleyes: I hope this helps Laugh | :laugh:

modified on Tuesday, January 11, 2011 1:45 PM

Generali want image should come from database from msaccess Pin
krunal108915-Sep-10 9:45
memberkrunal108915-Sep-10 9:45 
AnswerRe: i want image should come from database from msaccess Pin
IndomitablePhoenix11-Jan-11 8:55
memberIndomitablePhoenix11-Jan-11 8:55 
GeneralBlob Field Pin
enzo583-Aug-10 20:44
memberenzo583-Aug-10 20:44 
AnswerRe: Blob Field [modified] Pin
IndomitablePhoenix11-Jan-11 8:56
memberIndomitablePhoenix11-Jan-11 8:56 
GeneralMitico Pin
panicemi8-Jun-10 5:41
memberpanicemi8-Jun-10 5:41 
GeneralImage in Crystal Reports Pin
Huseyin Altindag16-Feb-10 10:12
memberHuseyin Altindag16-Feb-10 10:12 
GeneralRe: Image in Crystal Reports without logon to database popup Pin
Huseyin Altindag20-Feb-10 10:34
memberHuseyin Altindag20-Feb-10 10:34 
AnswerApply by use sub report no need to implement BLOB field Pin
pakpoompok10-Feb-10 16:43
memberpakpoompok10-Feb-10 16:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170326.1 | Last Updated 30 Oct 2007
Article Copyright 2007 by TangoCharli (Anant Tiwari)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid