Using RenderTargetBitmap on WindowsFormsHost

前端 未结 2 1321
天命终不由人
天命终不由人 2021-01-06 08:47

I have a set of controls inside a WindowsFormsHost and I would like to capture the current view and just save it as an image, I however only get some Pane

2条回答
  •  误落风尘
    2021-01-06 09:14

    A Windows Forms control also knows how to render itself, you don't have to jump through the screen capture hoop. Make it look like this:

        using (var bmp = new System.Drawing.Bitmap(basePanel.Width, basePanel.Height)) {
            basePanel.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height));
            bmp.Save(@"c:\temp\test.png");
        }
    

提交回复
热议问题