How to add System.Drawing.Image to C1FlexReport.Field.Picture?

Posted by: l.balazs on 11 July 2025, 8:55 am EST

    • Post Options:
    • Link

    Posted 11 July 2025, 8:55 am EST

    Hi,

    In .NET 8 the following statement causes run-time error in C1FlexReport8:

    private void PrintValue(C1.Win.FlexReport.Field field, System.Drawing.Image image)
    {
    ...
    	field.Picture = image;
    ...
    }

    Error = System.ArgumentException: ‘Invalid parameter for PictureHolder constructor.’

    Notes:

    1. The field .Picture has object type…
    2. This function just works fine up to .NET Framework 4.8.

    How can I fix this?

    Thanks,

    Louis

  • Posted 14 July 2025, 4:33 am EST

    Hello Louis,

    The Picture property used to take a System.Drawing.Image object before but now it takes a GrapeCity.Documents.Drawing.Image object.

    Please refer to Picture property for more information: https://developer.mescius.com/componentone/docs/reporting/online-flexreport/C1.FlexReport~C1.Report.ImageField~Picture.html

    So you can update your code as follows:

    private void PrintValue(C1.Win.FlexReport.Field field, System.Drawing.Image image)
    {
        using (var ms = new MemoryStream())
        {
            // Save the image as PNG to memory stream
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    
            // Convert to GcImage and assign to the field
            field.Picture = GrapeCity.Documents.Drawing.Image.FromBytes(ms.ToArray());
        }
    }

    Regards,

    Uttkarsh.

  • Posted 28 August 2025, 5:56 pm EST

    Hello,

    I’m using C1FlexReport 4.6.2 and C1.Report 4.6.2 in Version 2025_1 since today.

    With Version 2024_2 this code works:

    ((C1.Win.FlexReport.Field)flex_bericht.Fields["feld_foto"]).Picture = new Bitmap(foto);

    Today with the new versions mentioned above, I get this error:

    “Das Objekt des Typs “C1.Report.ImageField” kann nicht in Typ “C1.Win.FlexReport.Field” umgewandelt werden.”

    → “The object of type ‘C1.Report.ImageField’ cannot be converted to type ‘C1.Win.FlexReport.Field’.”

    I tried this:

    ((C1.Report.ImageField)flex_bericht.Fields["feld_foto"]).Picture = new Bitmap(foto);

    Now we have this error:

    “Invalid parameter for PictureHolder constructor.” Source:C1.Report.4.6.2

    This is the same error like in the first message of this thread!

    But I can’t use the solution because I’m on .Net Framework 4.6.2, not Net8 and have no GrapeCity.Documents.Drawing namespace available.

    Help would be very welcome!

    Michael

  • Posted 29 August 2025, 4:03 am EST - Updated 29 August 2025, 4:16 am EST

    My workaround is to save the image as file and use the file as source for the ImageField.

    ((C1.Report.ImageField)flex_bericht.Fields["feld_foto"]).Picture = $"{tempdir}{Path.DirectorySeparatorChar}{der_guid}.png";

    This works for now, but should not be the state of the C1 art.

    Michael

  • Posted 29 August 2025, 6:51 am EST

    Hello Michael,

    The GrapeCity.Documents.Drawing namespace is included with the C1.Win.FlexReport NuGet package.

    If you are working with local assemblies instead, please add references to DS.Document.Imaging and C1.Document.

    For reference, you can check the attached sample implementation: FlexReport_ResolveNamespace.zip.

    Regards,

    Uttkarsh.

  • Posted 29 August 2025, 7:33 am EST

    Hello Uttkarsh,

    thank you for the hints to add references to DS.Document.Imaging and C1.Document, because I use local assemblies. Now my code works in the modern way :_)

    You should update the .Net Framework documentation of C1FlexReport in this sense. It is in the state of 2024_2.

    Regards,

    Michael

  • Posted 1 September 2025, 12:12 am EST

    Hello Michael,

    We’re sorry, but if you check the remarks for the Picture property of ImageField, you’ll see that it does support the GrapeCity.Documents.Drawing.Image object:

    https://developer.mescius.com/componentone/docs/reporting/online-flexreport/C1.FlexReport~C1.Report.ImageField~Picture.html

    If you’re referring to any other documentation where this hasn’t been updated, could you please share the links so that we can review them and proceed accordingly?

    Regards,

    Uttkarsh.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels