Click here to Skip to main content
Licence 
First Posted 29 Oct 2007
Views 156,797
Downloads 8,097
Bookmarked 60 times

Image in Crystal Reports

By | 29 Oct 2007 | Article
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

About the Author

TangoCharli (Anant Tiwari)

Software Developer (Senior)

India India

Member

MCTS Microsoft Certified Technology Specialist
C-Dac
Computer Engineer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey19:13 23 Feb '12  
Generalwant image to be shown on special point of Report Pinmemberedinazem21:34 2 May '11  
GeneralMy vote of 5 Pingroupsohebrapati1:31 19 Mar '11  
AnswerSimple Solution - BlobField - How answered PinmemberIndomitablePhoenix12:02 10 Jan '11  
Generalpdf too large Pinmemberyi223:44 3 Oct '10  
AnswerRe: pdf too large [modified] PinmemberIndomitablePhoenix7:38 11 Jan '11  
Generali want image should come from database from msaccess Pinmemberkrunal10898:45 15 Sep '10  
AnswerRe: i want image should come from database from msaccess PinmemberIndomitablePhoenix7:55 11 Jan '11  
GeneralBlob Field Pinmemberenzo5819:44 3 Aug '10  
AnswerRe: Blob Field [modified] PinmemberIndomitablePhoenix7:56 11 Jan '11  
GeneralMitico Pinmemberpanicemi4:41 8 Jun '10  
GeneralImage in Crystal Reports PinmemberHuseyin Altindag9:12 16 Feb '10  
GeneralRe: Image in Crystal Reports without logon to database popup PinmemberHuseyin Altindag9:34 20 Feb '10  
AnswerApply by use sub report no need to implement BLOB field Pinmemberpakpoompok15:43 10 Feb '10  
GeneralBlob Field PinmemberMember 448541913:46 5 Dec '09  
GeneralRe: Blob Field PinmemberMember 60771752:49 16 Dec '09  
GeneralRe: Blob Field PinmemberMember 448541918:35 28 Dec '09  
AnswerRe: Blob Field - Answered PinmemberIndomitablePhoenix8:06 11 Jan '11  
Generalblob field object [modified] Pinmemberapol524 p14:22 4 Nov '09  
AnswerRe: blob field object - Answered PinmemberIndomitablePhoenix8:09 11 Jan '11  
GeneralGood job! PinmemberNguyennamhs21:48 27 Oct '09  
Generalhi Pinmembershrimast21:38 25 Sep '09  
GeneralDatabase Login Error PinmemberMATTXtwo19:19 26 May '09  
AnswerRe: Database Login Error - possible solution PinmemberIndomitablePhoenix8:12 11 Jan '11  
QuestionHow to display image in crystal report VS 2005 Pinmemberkiddsx4u9:42 17 Apr '09  

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.

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