Click here to Skip to main content
Click here to Skip to main content

Image in Crystal Reports

, 29 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

Introduction

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 
        dt.Rows.Add(drow); 
        // add row into the datatable 
        br.Close(); 
        // close the binary reader 
        fs.Close(); 
        // close the file stream 
        CrystalReport1 rptobj = new CrystalReport1(); 
        // object of crystal report 
        rptobj.SetDataSource(dt); 
        // 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

History

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

License

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

Share

About the Author

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

Comments and Discussions

 
QuestionNow working Pinmemberheemanshu bhalla25-Oct-13 4:17 
QuestionNot working Pinmemberheemanshu bhalla25-Oct-13 0:23 
GeneralMy vote of 5 PinmemberMember 937103828-Jun-13 0:13 
GeneralMy vote of 5 Pinmembersupriya chaladi28-Jan-13 22:12 
GeneralThnk u Pinmemberkiransolkar24-Dec-12 21:05 
QuestionBlob Field PinmemberRaghavendra Rao 55815-Nov-12 1:01 
Questiondatabase expert query PinmemberNikhil S Soni23-Oct-12 0:40 
AnswerRe: database expert query Pinmemberkiransolkar24-Dec-12 20:41 
GeneralMy vote of 5 Pinmembermanoj kumar choubey23-Feb-12 19:13 
Generalwant image to be shown on special point of Report Pinmemberedinazem2-May-11 21:34 
GeneralMy vote of 5 Pingroupsohebrapati19-Mar-11 1:31 
AnswerSimple Solution - BlobField - How answered PinmemberIndomitablePhoenix10-Jan-11 12:02 
Generalpdf too large Pinmemberyi23-Oct-10 23:44 
AnswerRe: pdf too large [modified] PinmemberIndomitablePhoenix11-Jan-11 7:38 
Generali want image should come from database from msaccess Pinmemberkrunal108915-Sep-10 8:45 
AnswerRe: i want image should come from database from msaccess PinmemberIndomitablePhoenix11-Jan-11 7:55 
GeneralBlob Field Pinmemberenzo583-Aug-10 19:44 
AnswerRe: Blob Field [modified] PinmemberIndomitablePhoenix11-Jan-11 7:56 
GeneralMitico Pinmemberpanicemi8-Jun-10 4:41 
GeneralImage in Crystal Reports PinmemberHuseyin Altindag16-Feb-10 9:12 
GeneralRe: Image in Crystal Reports without logon to database popup PinmemberHuseyin Altindag20-Feb-10 9:34 
AnswerApply by use sub report no need to implement BLOB field Pinmemberpakpoompok10-Feb-10 15:43 
GeneralBlob Field PinmemberMember 44854195-Dec-09 13:46 
GeneralRe: Blob Field PinmemberMember 607717516-Dec-09 2:49 
GeneralRe: Blob Field PinmemberMember 448541928-Dec-09 18:35 
AnswerRe: Blob Field - Answered PinmemberIndomitablePhoenix11-Jan-11 8:06 
Generalblob field object [modified] Pinmemberapol524 p4-Nov-09 14:22 
AnswerRe: blob field object - Answered PinmemberIndomitablePhoenix11-Jan-11 8:09 
GeneralGood job! PinmemberNguyennamhs27-Oct-09 21:48 
Generalhi Pinmembershrimast25-Sep-09 21:38 
GeneralDatabase Login Error PinmemberMATTXtwo26-May-09 19:19 
your code is good but the lack is that u have to provide the database definition file .ttx
so could u please alert me for this file..
mattrr85@yahoo.com
AnswerRe: Database Login Error - possible solution PinmemberIndomitablePhoenix11-Jan-11 8:12 
QuestionHow to display image in crystal report VS 2005 Pinmemberkiddsx4u17-Apr-09 9:42 
AnswerRe: How to display image in crystal report VS 2005 PinmemberDan Duggan26-Nov-09 6:42 
GeneralRe: How to display image in crystal report VS 2005 Pinmemberkrunal108915-Sep-10 10:30 
AnswerRe: How to display image in crystal report VS 2005 - two images at once - possible solutions PinmemberIndomitablePhoenix11-Jan-11 8:17 
GeneralRe: How to display image in crystal report VS 2005 Pinmemberrajnish2patel20-Dec-11 20:31 
GeneralAccess denied exception Pinmembernihad aliyev26-Nov-08 1:36 
AnswerRe: Access denied exception - FileMode for FileStream PinmemberIndomitablePhoenix11-Jan-11 8:29 
GeneralGreat !!! Pinmemberlcsistemas8-Oct-08 13:29 
Questionhow to make Image object on crystal report Pinmembernaveed8812-Sep-08 2:08 
AnswerRe: how to make Image object on crystal report Pinmemberhugoflores9-Apr-09 5:13 
GeneralRe: how to make Image object on crystal report PinmemberDan Duggan26-Nov-09 6:38 
AnswerRe: how to make Image object on crystal report - Answered PinmemberIndomitablePhoenix11-Jan-11 8:44 
GeneralImage in Crystal Reports Pinmemberdkinjal_2823-Jul-08 19:18 
AnswerRe: Image in Crystal Reports PinmemberIndomitablePhoenix11-Jan-11 8:38 
GeneralGreat PinmemberMember 458242511-Mar-08 5:15 

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

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

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