How to set Reporting Textbox Background Image on Linux?

1 Answer 21 Views
Styling
Preston
Top achievements
Rank 1
Preston asked on 19 Mar 2025, 08:20 PM

On Windows I am able to set the background image of a textbox with the following code:


using (var surface = SkiaSharp.SKSurface.Create(new SkiaSharp.SKImageInfo(100, 100)))
{
    Telerik.Reporting.Processing.TextBox textbox;

    using (var image = surface.Snapshot())
    using (var data = image.Encode())
    {
        byte[] imageData = data.ToArray();
 
        using (var ms = new MemoryStream(imageData))
        {
            textbox.Style.BackgroundImage.ImageData = System.Drawing.Image.FromStream(ms);
        }
    }
}

Image.FromStream has the following error:

"CA1416: This call site is reachable on all platforms. 'Image.FromStream(Stream)' is only supported on: 'windows' 6.1 and later."

What is the Linux compatible version of Image.FromStream()?

1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 21 Mar 2025, 12:34 PM

Hi Preston,

Thank you for providing the code snippet with your current approach.

Indeed, System.Drawing for .NET 8 and later is only supported on Windows due to a breaking change introduced by Microsoft. For other platforms, such as Linux, you can use our SkiaSharp-based graphics engine as a cross-platform alternative. I noticed that you are already using SkiaSharp in the code snippet, so I assume you have installed the Telerik.Drawing.Skia package, as outlined in the following documentation article:

That being said, to set the image dynamically using the Skia graphics engine (which is based on SkiaSharp instead of System.Drawing), you can use the DrawingFactory class to create an image from SKBitmap and then cast the result to Telerik.Drawing.ImageBase:

using (var surface = SkiaSharp.SKSurface.Create(new SkiaSharp.SKImageInfo(100, 100)))
{
    Telerik.Reporting.Processing.TextBox textbox = null;

    using (var image = surface.Snapshot())
    using (var data = image.Encode())
    {
        byte[] imageData = data.ToArray();

        using (var ms = new MemoryStream(imageData))
        {
            using (var skData = SKData.Create(ms))
            {
                using (var skImage = SKImage.FromEncodedData(skData))
                {
                    using (var skBitmap = SKBitmap.FromImage(skImage))
                    {
                        var imageBase = (Telerik.Drawing.ImageBase)Telerik.Drawing.Contract.DrawingFactory.CreateImage(skBitmap);
                        textbox.Style.BackgroundImage.ImageData = imageBase;
                    }
                }
            }
        }
    }
}

Could you please let me know if the above solution resolves the issue on your end? Looking forward to your response!

Regards,
Petar
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
Styling
Asked by
Preston
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or