• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Print image in Crystal using c#

I am using c# (VS2005) to print a crystal report using crystal that comes with VS2005.  My main problem is that I have to print one image in the header of the report However this image will change with each report so I have to pass the path of the image to the report somehow.  Can someone help please?
0
dbdp
Asked:
dbdp
  • 8
  • 4
  • 3
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
dbdpAuthor Commented:
Could yopu explain that in c#?
0
 
Éric MoreauSenior .Net ConsultantCommented:
As I am not fluent in C# and I don't have a spare hour in front of me, I wouldn't try to convert it to C#. If you know C# well, you can surely do it in less then 10 minutes since there are about 10 lines to that job.

The idea is to feed a dataset with a stream containing your image and provide it to CR.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dbdpAuthor Commented:
I am following above examples - including the vb one but for some reason cannot get to work.  Any ideas?
0
 
mlmccCommented:
PLease show your code.

mlmcc
0
 
dbdpAuthor Commented:
DataSet CreateData()
        {
            string sItemNumber = "";
            string sDescription = "";
            string sQty = "";
            decimal dQty = 0;
            string sPrice = "";
            decimal dPrice = 0;
           
            DataSet dsReceipt = new DataSet();

            // add a table 'Images' to the dataset
            dsReceipt.Tables.Add("dtBarcode");
           
            dsReceipt.Tables["dtBarcode"].Columns.Add("Receipt", System.Type.GetType("System.String"));
            dsReceipt.Tables["dtBarcode"].Columns.Add("Barcode", System.Type.GetType("System.Byte[]"));


            AddImageRow(dsReceipt.Tables["dtBarcode"], sReceipt, Directory.GetCurrentDirectory() + "\\Barcode.bmp");

            dsReceipt.Tables.Add("dtItems");

            // add two fields
            //dsReceipt.Tables[0].Columns.Add("Country", System.Type.GetType("System.String"));
            dsReceipt.Tables["dtItems"].Columns.Add("Receipt", System.Type.GetType("System.String"));
            dsReceipt.Tables["dtItems"].Columns.Add("ItemNumber", System.Type.GetType("System.String"));
            dsReceipt.Tables["dtItems"].Columns.Add("Description", System.Type.GetType("System.String"));
            dsReceipt.Tables["dtItems"].Columns.Add("Qty", System.Type.GetType("System.Decimal"));
            dsReceipt.Tables["dtItems"].Columns.Add("Price", System.Type.GetType("System.Decimal"));

            for (int iDG = 0; iDG < dataGridView1.RowCount; iDG++)
            {

                sItemNumber = dataGridView1[0, iDG].Value.ToString().Trim();
                sDescription = dataGridView1[1, iDG].Value.ToString().Trim();
                sQty = dataGridView1[2, iDG].Value.ToString();
                sPrice = dataGridView1[3, iDG].Value.ToString();
                dQty = 0;
                dPrice = 0;
                decimal.TryParse(sQty, out dQty);
                decimal.TryParse(sPrice, out dPrice);
                AddRow(dsReceipt.Tables["dtItems"], sReceipt, sItemNumber, sDescription, dQty, dPrice);
            }
            return (dsReceipt);
        }

        void AddImageRow(DataTable tbl, string name, string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Open);      // create a file stream
            BinaryReader br = new BinaryReader(fs);                                    // create binary reader
            DataRow row;

            // create a new datarow
            row = tbl.NewRow();

            // set country field and image field
            row[0] = name;
            row[1] = br.ReadBytes((int)br.BaseStream.Length);

            // add this row to the table
            tbl.Rows.Add(row);

            // clean up
            br = null;
            fs = null;
        }

void AddRow(DataTable tbl, string sReceipt, string sItemNumber, string sDescription, decimal dQty, decimal dPrice)
        {
            DataRow row;

            row = tbl.NewRow();

            row[0] = sReceipt;
            row[1] = sItemNumber;
            row[2] = sDescription;
            row[3] = dQty;
            row[4] = dPrice;

            // add this row to the table
            tbl.Rows.Add(row);

            // clean up
        }

        private void btnPrintReceipt_Click(object sender, EventArgs e)
        {
            rptChit CHIT = new rptChit();
            CHIT.SetDataSource(CreateData());
            CHIT.PrintToPrinter(0, false, 1, 1);
        }
0
 
Éric MoreauSenior .Net ConsultantCommented:
your image may be invalid. Try with the images I have provided in my link.
0
 
dbdpAuthor Commented:
In what way could it be invalid?
0
 
Éric MoreauSenior .Net ConsultantCommented:
wrong format. I had problems with many pictures. The most standards are bmp.
0
 
dbdpAuthor Commented:
It is BMP.

The picture appears blank on report
0
 
dbdpAuthor Commented:
It does have to do with the format - but I can't see how - I must be creating a wrong bmp somehow but I can't undarstan - any tips?
0
 
dbdpAuthor Commented:
There is a new twist - I have been playing around with the size of the picture and it has gone from a blank pic to an all black pic - what is going on?
0
 
dbdpAuthor Commented:
It was indeed a wong image format - the image had to be flattened
0
 
mlmccCommented:
Glad i could hep

mlmcc
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now