Click here to Skip to main content
Licence 
First Posted 30 Oct 2007
Views 145,736
Downloads 6,509
Bookmarked 58 times

Image in Crystal Reports

This is sample small project to display image in crystal report
2 votes, 11.1%
1

2
2 votes, 11.1%
3
3 votes, 16.7%
4
11 votes, 61.1%
5
4.27/5 - 18 votes
2 removed
μ 3.45, σa 2.39 [?]
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
Generalwant image to be shown on special point of Report Pinmemberedinazem22:34 2 May '11  
GeneralMy vote of 5 Pingroupsohebrapati2:31 19 Mar '11  
AnswerSimple Solution - BlobField - How answered PinmemberIndomitablePhoenix13:02 10 Jan '11  
Generalpdf too large Pinmemberyi20:44 4 Oct '10  
AnswerRe: pdf too large [modified] PinmemberIndomitablePhoenix8:38 11 Jan '11  
Generali want image should come from database from msaccess Pinmemberkrunal10899:45 15 Sep '10  
AnswerRe: i want image should come from database from msaccess PinmemberIndomitablePhoenix8:55 11 Jan '11  
GeneralBlob Field Pinmemberenzo5820:44 3 Aug '10  
AnswerRe: Blob Field [modified] PinmemberIndomitablePhoenix8:56 11 Jan '11  
GeneralMitico Pinmemberpanicemi5:41 8 Jun '10  
GeneralImage in Crystal Reports PinmemberHuseyin Altindag10:12 16 Feb '10  
GeneralRe: Image in Crystal Reports without logon to database popup PinmemberHuseyin Altindag10:34 20 Feb '10  
AnswerApply by use sub report no need to implement BLOB field Pinmemberpakpoompok16:43 10 Feb '10  
GeneralBlob Field PinmemberMember 448541914:46 5 Dec '09  
GeneralRe: Blob Field PinmemberMember 60771753:49 16 Dec '09  
GeneralRe: Blob Field PinmemberMember 448541919:35 28 Dec '09  
AnswerRe: Blob Field - Answered PinmemberIndomitablePhoenix9:06 11 Jan '11  
Generalblob field object [modified] Pinmemberapol524 p15:22 4 Nov '09  
AnswerRe: blob field object - Answered PinmemberIndomitablePhoenix9:09 11 Jan '11  
GeneralGood job! PinmemberNguyennamhs22:48 27 Oct '09  
Generalhi Pinmembershrimast22:38 25 Sep '09  
GeneralDatabase Login Error PinmemberMATTXtwo20:19 26 May '09  
AnswerRe: Database Login Error - possible solution PinmemberIndomitablePhoenix9:12 11 Jan '11  
QuestionHow to display image in crystal report VS 2005 Pinmemberkiddsx4u10:42 17 Apr '09  
AnswerRe: How to display image in crystal report VS 2005 PinmemberDan Duggan7:42 26 Nov '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
Web01 | 2.5.120209.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