Adding Bitmap column to the report results in exception

Hello,

I need to put images into the Report.

This is how I add my data to the report.
   DataSet set = new DataSet("Analysis");
   DataTable table = new DataTable("Prescription");
   table.Columns.Add("Dosage", typeof(int));
   table.Columns.Add("Drug", typeof(string));
   table.Columns.Add("Patient", typeof(string));
   table.Columns.Add("Date", typeof(DateTime));
   table.Columns.Add("Image", typeof(Bitmap));

   table.Rows.Add(25, "Indocin", "David", DateTime.Now, BitmapFromBitmapSource(analysis.Containers[0].Picture.bitmap));

All seems to work fine, but on Report preview I get the following exception:
System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
   at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(Stream stream, ImageFormat format)
   at LJq97BqNfhDBrWDL44.Bs6RPQ9dnFvpdU2SVr.F2coevif0(Image  , Stream  , ImageFormat  )
   at FastReport.PictureObject.Serialize(FRWriter writer)
   at FastReport.Utils.FRWriter.Write(IFRSerializable obj, Object diff)
   at FastReport.Utils.FRWriter.Write(IFRSerializable obj)
   at iMpcT7FWOi3nF4dvsFN.pKH0WXF7BLDue8VV6KZ.T7E2zBtlqvC(Base  , XmlItem  )
   at iMpcT7FWOi3nF4dvsFN.pKH0WXF7BLDue8VV6KZ.T7E2zBtlqvC(Base  , XmlItem  )
   at iMpcT7FWOi3nF4dvsFN.pKH0WXF7BLDue8VV6KZ.pxd2zHoEBq6(BandBase  )
   at FastReport.Preview.PreparedPages.AddBand(BandBase band)
   at FastReport.Engine.ReportEngine.rZK7T5KYOI(BandBase  )
   at FastReport.Engine.ReportEngine.mGs7YnYVbf(BandBase  , Boolean  )
   at FastReport.Engine.ReportEngine.J7377McmnA(BandBase  , Boolean  )
   at FastReport.Engine.ReportEngine.ShowBand(BandBase band)
   at FastReport.Engine.ReportEngine.hjo7uwpM11(DataBand  , Int32  )
   at FastReport.Engine.ReportEngine.MFT7b1SYnC(DataBand  , Int32  , Boolean  , Boolean  )
   at FastReport.Engine.ReportEngine.Vkw7nxWo1t(DataBand  )
   at FastReport.Engine.ReportEngine.R7y9xGnb5S(BandCollection  )
   at FastReport.Engine.ReportEngine.Sgd9IAJfco(ReportPage  )
   at FastReport.Engine.ReportEngine.eo692vGe00()
   at FastReport.Engine.ReportEngine.f747QvKEgI(ReportPage  )
   at FastReport.Engine.ReportEngine.Gd676X6KgR(Boolean  , Boolean  , Boolean  , ReportPage  )
   at FastReport.Engine.ReportEngine.Crh7BGcFCI(Boolean  , Boolean  , Boolean  )
   at FastReport.Report.Prepare(Boolean append)
   at FastReport.Report.Prepare()
   at Dmp1CFjdpWXGsfSJaxN.fKVqNSjHKkBKo69fyXb.DxUIa7IWsVw()
Oddly if I leave the error message open and switch a few times through my windows I can see the image on the designer. On closing the error window it vanishes.

I am using the FastReport .net Demo.

Thank you for your help,
Samser

Comments

  • edited 8:25PM
    To display picture programmatically, i tried this code below (and success)

    in your .net :
    using (DataTable dt = new DataTable())
    {
        dt.Load(dr);
        dt.TableName = "MainReport";
    
        byte[] yourpic = System.IO.File.ReadAllBytes(@"D:\gl2016_csharp\gl\Resources\yourpic.png");
                                    
    
        dt.Columns.Add("Test", System.Type.GetType("System.Byte[]"));
        foreach (DataRow row in dt.Rows)
        {
            row[10] = yourpic;
        }
    
        FastReport.Report report = new FastReport.Report();
        using (System.IO.Stream ms = new System.IO.MemoryStream(GL.Properties.Resources.rptCOA))
        {
            report.Load(ms);
        }
        report.RegisterData(dt, dt.TableName);
        report.Prepare();
        PreviewControl1.AddTab(report, report.FileName);
        PreviewControl1.ZoomPageWidth();
    }
    

    in frx file :
      <Dictionary>
        <TableDataSource Name="MainReport" ReferenceName="MainReport" DataType="System.Int32" Enabled="true">
          <Column Name="Acc0Urut" DataType="System.Int32"/>
          <Column Name="Acc0Code" DataType="System.String"/>
          <Column Name="Acc1Urut" DataType="System.Int32"/>
          <Column Name="Acc1Code" DataType="System.String"/>
          <Column Name="Acc2Urut" DataType="System.Int32"/>
          <Column Name="Acc2Code" DataType="System.String"/>
          <Column Name="Acc3Code" DataType="System.String"/>
          <Column Name="Acc3Name" DataType="System.String"/>
          <Column Name="Acc3FC" DataType="System.Boolean"/>
          <Column Name="Acc3Blc" DataType="System.Boolean"/>
          <Column Name="Test" DataType="System.Byte[]"/>
        </TableDataSource>
      </Dictionary>
    

    in frx file, databand :
    <PictureObject Name="Picture1" Left="22.68" Top="-3.78" Width="75.6" Height="75.6" SizeMode="Normal" DataColumn="MainReport.Test"/>
    
  • edited 8:25PM
    This works! Thank you very much!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.