How to use System.Drawing.Image in RDLC Image Control?

Is it possible to use System.Drawing.Image in RDLC Image Control? All I read was 3 methods:

  • database
  • embedded resource
  • external file

Thank you.

EDIT: Following this .NET or C # library for the CGM format (computer graphics metadata)? Now I got the image in System.Drawing.Image format and I want to display it as part of the report (as an image) --- what I want to do.

+6
image rdlc
source share
3 answers

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

Something like:

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

In the report you can get an image as if from a database

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

The shell looks something like this:

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

I use this quite often. This has the advantage that I do not need to add an image to db or add it as a resource of each report. In addition, the application can tell which image should be used. Please note that this image format must be known from rdlc-engine. The final question is how to convert the system.drawing.image file to an array of bytes. I work with WPF and therefore I do not know. But I'm sure google will answer this question very reliably.

+4
source share

You can use the database source parameter along with the parameters to dynamically set the image source from byte arrays.

Code for:

 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 property of the image value to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)

3- Set the MIME Type property to

 =Parameters!MIMEType.Value 

4- Use the database as a source

How to make a PNG image (like a memory stream) on a .NET ReportViewer report surface

+2
source share


I'm not quite sure what you want to do with this, but overall this is not possible. Shortcut management is just an image holder in RDLC files. These 3 parameters determine the location from where the image control receives an image that is displayed from a database, embedded resource, or external file. If you give me more information about what you want to achieve, I can give you some kind of solution.
Best wishes,
Jordan

0
source share

All Articles