2016-09-26 8 views
0

私は2つのコントロール画像ビューとキャンバスを持っています。 イメージの上に私は矩形を描画しています。スクリーンショットを撮っている間、私は矩形ではなくイメージを取得しています。コードの下に使用WPFのScreenShot

iは

int Width = (int)canvas1.RenderSize.Width; 
      int Height = (int)canvas1.RenderSize.Height; 
RenderTargetBitmap renderTargetBitmap = 
new RenderTargetBitmap(Width, Height, 96, 96, PixelFormats.Pbgra32); 
      renderTargetBitmap.Render(canvas1); 
      PngBitmapEncoder pngImage = new PngBitmapEncoder(); 
      pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); 
      using (Stream fileStream = File.Create(filePath)) 
      { 
       pngImage.Save(fileStream); 

      } 

私はイメージ画像のみでキャンバスを交換していた場合には来ている黒画像を取得しています。 両方のコントロールを含むスクリーンショットを撮るには?

+0

画像にキャンバス、キャンバス、画像に長方形をハードコードしました。あなたのコードは、Button.Clickの中で私のためにうまくいきます。 – AnjumSKhan

+0

はスクリーンショットを撮ることができますか? –

+0

矩形で画像を保存できます。 – AnjumSKhan

答えて

1

renderのスクリーンショットを撮る前にレンダリングを完了してからno-opとなります。 また、ビューポート に描画された長方形を表示することができ、スクリーンショットには表示されないことが前提です。矩形の色が画像の背景と異なるかどうかを確認してください。

renderTargetBitmap.Render(canvas1); 
//no-op for rendering to complete before taking screenshot. 
_dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { })); 
//screenshot code here. 
+0

キャンバスがあるイメージビューがあります。キャンバス上に描画矩形です。私はスクリーンショットを取っているイメージだけです。 –