Dynamically change an image in a Crystal Report at runtime

后端 未结 8 1257
天命终不由人
天命终不由人 2021-02-04 08:08

I\'m using the Crystal Reports included with VisualStudio 2005. I would like to change the image that is displayed on the report at runtime ideally by building a path to the ima

8条回答
  •  心在旅途
    2021-02-04 08:58

    I finally reached a solution using the byte[] tip posted here by Josh.

    This solution applies if you are using a plain old C# Object to populate your Crystal Reports (see http://www.aspfree.com/c/a/C-Sharp/Crystal-Reports-for-Visual-Studio-2005-in-CSharp/ for info on this approach).

    In your C# class, insert the following code:

    private static byte[] m_Bitmap = null;
    
    public byte[] Bitmap
    {
       get
       {
          FileStream fs = new FileStream(bitmapPath, FileMode.Open);
          BinaryReader br = new BinaryReader(fs);
          int length = (int)br.BaseStream.Length;
          m_Bitmap = new byte[length];
          m_Bitmap = br.ReadBytes(length);
          br.Close();
          fs.Close();
          return m_Bitmap;
       }
    }
    

    Now, update your C# Object Mapping in CR using the "Verify Database" option. You should then see the Bitmap property as a CR field. Just drag it onto the form. It will be of type IBlobFieldObject. When you run, you should see your image.

提交回复
热议问题