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.

Need extra support?

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

Learn More

Forum Channels