Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Adding Images to Report
posted

Hi,

I am trying to create a report in our Silverlight application and add an image to that report but for some reason, when ever I create the Image (Infragistics.Documents.Reports.Graphics) object, my Data, Width and Height are always 0. even though I pass in a byte array with data in it.

The image I am trying to add to the report is an image of the xamWebChart.

Here's the code:

Report report = new Report();
ISection reportSection = report.AddSection();
IBand reportBand = reportSection.AddBand();

//this would have some content in it.
XamWebChart chart = new XamWebChart();
WriteableBitmap
 bitmap = new WriteableBitmap(chart, null); byte[] imageByte = bitmap.ToByteArray(); using (MemoryStream stream = new MemoryStream(imageByte)) {    Image image = new Image(System.Drawing.Image.FromStream(stream), true); var reportImage = reportBand.AddImage(image); reportImage.KeepRatio = true; }

The .ToByteArray() method basically converts that WriteableBitmap into a byte[]:

public static byte[] ToByteArray(this WriteableBitmap bmp)
{
   int[] p = bmp.Pixels;
   int len = p.Length << 2;
   byte[] result = new byte[len];
   Buffer.BlockCopy(p, 0, result, 0, len);
   return result;
}

Is there a proper way to add an image to the report in silverlight?  Thanks!

Parents
No Data
Reply
  • 2848
    posted

    Hi,

     

    The Infragistics.Documents is only shipped by the Reporting product to be used internally, as part of the PDF-exporting functionality, it’s not meant to be used directly.

     

    You can create a report that includes a chart, and then export it to PDF. In order to export it, you need to include a XamReportViewer on your page and then use the Export method, for instance:

     

            var dialog = new SaveFileDialog();

            var result = dialog.ShowDialog();

     

            if (result.HasValue && result.Value)

            {

                var stream = dialog.OpenFile();

     

                // ReportViewer is the XamReportViewer instance that was inserted on the page

                ReportViewer.Export(stream, "PDF");

                ReportViewer.ExportCompleted += ExportCompleted;

            }

     

    Since the export process is asynchronous, you also need to close the stream once export is completed:

     

            private void ExportCompleted(object sender, ExportCompletedEventArgs e)

            {

                ReportViewer.ExportCompleted -= ExportCompleted;

     

                e.Stream.Close();

            }

     

    If you don’t want to show the Report Viewer in the page, you can set the opacity to zero, as it needs to be present in the Silverlight visual tree.

     

    Regards,

    Andres

Children