打印窗口WPF / DirectX

jyztefdp  于 11个月前  发布在  其他
关注(0)|答案(3)|浏览(135)

有谁知道一种可靠地获取WPF窗口快照的方法吗?PrintWindow API适用于“标准”win32窗口,但由于WPF使用DirectX,PrintWindow无法捕获图像。我认为需要获取与窗口关联的DirectX对象的前端缓冲区,但我不知道如何做到这一点。

fd3cxomn

fd3cxomn1#

我不确定这是否是你的意思,我不确定我是否被允许链接到我的博客,但是this有用吗?它基本上使用RenderTargetBitmap来生成JPG。你可以用它来“截图”整个窗口,然后打印出来。

u59ebvdq

u59ebvdq2#

此方法应可帮助您打印整个WPF / XAML窗口

private void PrintWindow(PrintDialog pdPrint, 
                         System.Windows.Window wWin, 
                         string sTitle, 
                         System.Windows.Thickness? thMargin)
    {
        Grid drawing_area = new Grid();
        drawing_area.Width = pdPrint.PrintableAreaWidth;
        drawing_area.Height = pdPrint.PrintableAreaHeight;

        
        Viewbox view_box = new Viewbox();
        drawing_area.Children.Add(view_box);
        view_box.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
        view_box.VerticalAlignment = System.Windows.VerticalAlignment.Center;

        if (thMargin == null)
        {
            view_box.Stretch = System.Windows.Media.Stretch.None;
        }
        else
        {
            
            view_box.Margin = thMargin.Value;
            view_box.Stretch = System.Windows.Media.Stretch.Uniform;
        }

        
        VisualBrush vis_br = new VisualBrush(wWin);

        
        System.Windows.Shapes.Rectangle win_rect = new System.Windows.Shapes.Rectangle();
        view_box.Child = win_rect;
        win_rect.Width = wWin.Width;
        win_rect.Height = wWin.Height;
        win_rect.Fill = vis_br;
        win_rect.Stroke = System.Windows.Media.Brushes.Black;
        win_rect.BitmapEffect = new System.Windows.Media.Effects.DropShadowBitmapEffect();

        // Arrange to produce output.
        Rect rect = new Rect(0, 0, pdPrint.PrintableAreaWidth, pdPrint.PrintableAreaHeight);
        drawing_area.Arrange(rect);

        // Print it.
        pdPrint.PrintVisual(drawing_area, sTitle);

    }

字符串

相关问题