示例#1
0
        private BitmapSource RenderControl(WinForms.Control control)
        {
            if (control == null || control.Width == 0 || control.Height == 0)
            {
                return(null);
            }

            if (Buffer == null || Buffer.Width < control.Width || Buffer.Height < control.Height)
            {
                var dpi = DisplayInfo.FromPresentationSource(PresentationSource.FromVisual(Image));
                Buffer = new InteropBitmap(control.Width, control.Height, (float)dpi.DpiX, (float)dpi.DpiY, InteropBitmapFormat.Rgba32);
            }

            Buffer.Render(target => control.DrawToBitmap(target, control.Bounds));

            return(Buffer.Bitmap);
        }