简体   繁体   中英

insert dynamic images in a crystal reports page from the image folder

Is there a way to insert images dynamically in a Crystal Reports page from an images folder?

The exact requirement is to display a company's logo at the top of every crystal report page and when they change, ie when you have a new logo , you only change the image(.jpg) in the images folder and the corresponding image in all the reports should change.

How do I achieve this in C#?

I'm posting the answer i got, hope this would be helpful for others.

private void getImage()
    {
        FileStream fs;
        fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "img\\cube.png", FileMode.Open);
        BinaryReader BinRed = new BinaryReader(fs);
        try
        {
            CreateTable();
            DataRow dr = this.DsImages.Tables["images"].NewRow();
            dr["image"] = BinRed.ReadBytes((int)BinRed.BaseStream.Length);
            this.DsImages.Tables["images"].Rows.Add(dr);

            //FilStr.Close();
            BinRed.Close();

            DynamicImageExample DyImg = new DynamicImageExample();
            DyImg.SetDataSource(this.DsImages);
            this.crystalReportViewer1.ReportSource = DyImg;
        }
        catch (Exception er)
        {
            MessageBox.Show(er.Message, "Error");
        }
    }

In CR you can do this by: Inserting a placeholder image in your report at the position and size you want it. Right-click on it and select "Format Graphic" -> Go to the "Picture" tab -> Enter a formula in the "Graphic Location" that will return the desired file path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM