Image is not created or loaded into a GcBitmap

Posted by: richard.beacroft on 5 August 2021, 6:31 am EST

  • Posted 5 August 2021, 6:31 am EST

    We are receiving the following error.

    Image is not created or loaded into a GcBitmap. at GrapeCity.Documents.Imaging.GcBitmap.SetDpi(Single dpiX, Single dpiY)

                
                using (var gchtml = new GcHtmlRenderer(html))
                {
                    using (GcBitmap b = new GcBitmap())
                    {
                        gchtml.RenderToGcBitmap(b, new HtmlToImageFormat(true, true)
                        {
                            WindowSize = new Size(414, 896), // size of browser window
                            DefaultBackgroundColor = Color.Empty, // this will be inferred from the HTML
                            MaxLeftMargin = 125,
                            MaxRightMargin = 125
                        });
    
                        b.SetDpi(300); // default resize pixel width and height is proportionate to 300DPI taken from google page found
    
                        using (var resizedBitmap = Resize(b, new Size(650, 5610)))
                        {
                            resizedBitmap.SaveAsPng(filePath);
                        }
                    }
                }
    
    

    The contents of the html variable is attached

    We are using NuGet libraries:

    1. GrapeCity.Documents.Html version: 4.1.0.663.
    2. GrapeCity.Documents.Html.Windows.X64 version: 4.1.0.663
    3. NetStandard.Library version 2.0.3

    Please can you advise as to what is wrong with the above code.

    NOTE: This code works for most HTML, but not others, like the attached file

  • Posted 6 August 2021, 2:07 am EST

    Hello Richard,

    Sorry, we do not face the issue with the attached HTML file in your support query.

    We do not see any Resize method in your given code snippet so we used the above given stripped-down code by removing Resize method call but the HTML file is saved successfully to PNG. Please find the attached sample implementing the same.

    If you are doing anything else then please modify the sample accordingly so that we can replicate the issue at our end and assist you better.

    regards,

    Prabhat Sharma.

    HTMLImageDemo.zip

Need extra support?

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

Learn More

Forum Channels