从图像文件夹中插入水晶报表页中的动态图像。

时间:2021-12-01 05:55:12

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, i.e 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.

确切的要求是在每个水晶报表页的顶部显示一个公司的标志,当它们改变时,我。当你有一个新的标志时,你只改变图像文件夹中的图像(.jpg),所有报告中的对应图像都应该改变。

How do I achieve this in C#?

如何在c#中实现这一点?

2 个解决方案

#1


1  

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");
        }
    }

#2


0  

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.

在CR中,您可以这样做:将占位符映像插入到报表中所需的位置和大小。右键单击它并选择“Format Graphic”—>转到“Picture”选项卡—>在“Graphic Location”中输入一个公式,该公式将返回所需的文件路径。

#1


1  

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");
        }
    }

#2


0  

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.

在CR中,您可以这样做:将占位符映像插入到报表中所需的位置和大小。右键单击它并选择“Format Graphic”—>转到“Picture”选项卡—>在“Graphic Location”中输入一个公式,该公式将返回所需的文件路径。