How to get the visual's snapshot in wpf? Do not use RenderTargetBitmap

I can use RenderTargetBitmap to get the visual's snapshot, but
RenderTargetBitmap use software render only. So it is very slow. When I
get a snapshot of a complicate visual element, it may cost 0.7s. Does
anyone has the faster way to do this

System.Windows.Media.Imaging.RenderTargetBitmap bitmapImage = new System.Windows.Media.Imaging.RenderTargetBitmap(
(int)(width),
(int)(height),
96, 96, PixelFormats.Default);
bitmapImage.Render(this); // code of this line will cost about 0.7s




Answer this question

How to get the visual's snapshot in wpf? Do not use RenderTargetBitmap

  • R.Tutus

    I think you can use P/Invoke to call the unmanaged USER/GDI APIs, you can first grab the HDC for the target window, and then copy those bits from the source HDC to the destination HDC using BitBlt, and since BitBlt can let you specify the source rectangle which you wanna those pixels copied from, you can actually calculate the actual bounding box of your target visual, then you can get the snapshot of the targeting visual not the whole window.

    Sheva


  • How to get the visual's snapshot in wpf? Do not use RenderTargetBitmap