CefSharp WpfControl and rendering to image

做~自己de王妃 提交于 2019-12-20 06:27:18

问题


We want to show a webpage in a chromium based browser within a wpf application. The website that is displayed within the browser should also be shown on another screen but without interaction. I want to combine the cefsharp wpf browser control and the cefsharp offscreen rendering.

Can I use one chromium instance for displaying the page with interactions in wpf and export the current visible website as an image?

Thank you and best regards,

Simon


回答1:


Thank you amatiland, it indeed works with the OnPaint Method or Event.

    public MainWindow()
    {
        InitializeComponent();

        Browser.Paint += Browser_Paint;
    }

    void Browser_Paint(object sender, CefSharp.Wpf.PaintEventArgs e)
    {
        Bitmap newBitmap = new Bitmap(e.Width, e.Height, 4 * e.Width, System.Drawing.Imaging.PixelFormat.Format32bppRgb, e.Buffer);

        var aPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "TestImageCefSharpQuant.png");
        newBitmap.Save(aPath);
    }

XAML

    <wpf:ChromiumWebBrowser x:Name="Browser" Address="www.google.com"></wpf:ChromiumWebBrowser>


来源:https://stackoverflow.com/questions/54231784/cefsharp-wpfcontrol-and-rendering-to-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!