2009-01-05 37 views
3

任何人都知道的一種方式,以可靠地將一個WPF窗口的快照?該PrintWindow API非常適用於「標準」的win32窗口,但由於WPF使用DirectX,PrintWindow無法捕捉到的圖像。我認爲一個人需要抓住與窗口關聯的某個DirectX對象前緩衝區,但我不知道該怎麼做。PrintWindow WPF/DirectX的

謝謝!

+0

只是爲了澄清 - 我在找工作方式類似於PrintWindow的解決方案 - 即我應該能夠從另一個過程只用HWND的捕捉截屏WPF窗口。 – 2009-01-05 16:24:48

回答

3

我不知道,如果這是你的意思,我不知道我被允許鏈接到我的博客或沒有,但就是this什麼用處?它基本上使用RenderTargetBitmap來生成JPG。你可以用它來「截圖」整個窗口然後打印。

如果這是違反規定的,有人隨意刪除:)

+0

謝謝史蒂夫。這不適合我的情況 - 我會更新我的問題,因爲它不清楚。基本上,我希望能夠通過訪問Hwnd和其他進程來捕獲此映像。 – 2009-01-05 16:23:10

+0

啊,對不起,那麼不知道。我從應用內完成了DirecX屏幕截圖,但從未遠程執行。該代碼最初是爲遠程屏幕截圖編寫的,但它使用了自我託管的WCF服務,我認爲這對您沒有好處? – 2009-01-05 17:38:41

1

這種方法應該可以幫助您打印整個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); 

    } 

問候肖恩·坎貝爾

相關問題