6

Is it possible to use System.Drawing.Image in an RDLC Image Control? All I have been reading were 3 methods:

  • database
  • embeded resource
  • external file

Thank you thank you.

EDIT: Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.

Community
  • 1
  • 1
Jake
  • 11,273
  • 21
  • 90
  • 147

3 Answers3

4

Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.

Something like:

 ReportDataSource logoDataSource = new ReportDataSource();
 logoDataSource.Name = "LogoDS";
 logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
 localReport.DataSources.Add(logoDS);

In the report you then you can the image as it were from the database

 =First(Fields!LogoByteArrayProperty.Value, "LogoDS")

The wrapper looks something like:

 class LogoWrapper{
   ...
   public byte[] LogoByteArrayProperty{
      get{ 
         // Return here the image data
      }
   }
 }

I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used. Please note, the given image format must be known from the rdlc-engine. The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.

HCL
  • 36,053
  • 27
  • 163
  • 213
  • This is interesting.. i'll give it a try first and get back. Thanks. – Jake Feb 11 '11 at 10:31
  • Thanks it worked! Just want to add that it appears that the RDLC image control also accepts byte[] array as value so long as mime type of the control is set correctly. This would be the forth way to do it. – Jake Feb 12 '11 at 11:09
2

You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.

Code Behind:

var param2 = new ReportParameter()
               {
                   Name = "CompanyLogo",
                   Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
               };
                ReportViewer1.LocalReport.SetParameters(param2);

rdlc File:

1- Add Text Parameters 'CompanyLogo' and 'MIMEType'

2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)

3- Set MIME Type Property to

=Parameters!MIMEType.Value

4- Use 'Database' As Source

How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface

Community
  • 1
  • 1
0


i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan

IordanTanev
  • 6,130
  • 5
  • 40
  • 49
  • Hi Lordan, I just edited my post. It's quite straight forward, just want to use the Image as the image! So I can dynamically generate images to print. – Jake Feb 11 '11 at 10:31