How to print Picture in Crystal Report 8.5

Swapnil Salunke replied to Atheeq Ahmed at 16-Jun-08 01:35
Hello Atheeq Ahmed

You can try this way
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
More code sample from  Anant Tiwari at
http://www.codeproject.com/KB/vb/Image_in_Crystal_Reports.aspx
This also can be referred
http://www.mcawp.net/download/Tutorial.pdf
http://www.codeguru.com/forum/printthread.php?t=449369
http://visualbasic.ittoolbox.com/groups/technical-functional/vb-crystalreports-l/printing-pictures-in-crystal-reports-80-247818

Hope it helps you
Happy Coding takecare

Click here to sign in and reply. You could earn money via our $500 contest just for being helpful.
  How to print Picture in Crystal Report 8.5 - Atheeq Ahmed  16-Jun-08 12:44 12:44:48 AM
      Here is the code to print picture in crystal report - Sujit Patil  16-Jun-08 01:06 1:06:11 AM
      Binary format - sri sri  16-Jun-08 01:31 1:31:30 AM
          I need this coding in vb.net - Picture print in crystal rep 8,5 - Atheeq Ahmed  18-Jun-08 01:38 1:38:18 AM
      How to print Picture in Crystal Report 8.5 - Swapnil Salunke  16-Jun-08 01:35 1:35:23 AM
      try this... - Vasanthakumar D  16-Jun-08 01:42 1:42:04 AM
      change image at runtime - sundar k  16-Jun-08 04:26 4:26:18 AM
      re: - alice johnson  16-Jun-08 12:00 12:00:30 PM
View Posts