开发者

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

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 r开发者_如何学Pythoneport (as an image) --- that's what I want to do.


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.


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



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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜