DXSceneRender |
public void RenderToBitmap( int width, int height, int preferedMultisampling, BackBufferReadyEventHandler renderedTextureReadyCallback )
The following code uses RenderToBitmap to render to WPF's WriteableBitmap:
var writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null); this.DXScene.RenderToBitmap(width, height, preferedMultisampling, delegate (object sender, BackBufferReadyEventArgs e) { // delegate used by RenderToBitmap method - it is called when the scene is rendered to back buffer and it is available in main CPU memory writeableBitmap.Lock(); var viewportRect = new Int32Rect(0, 0, e.Width, e.Height); // Copy bitmap from e.Data.DataPointer to writeableBitmap writeableBitmap.WritePixels(viewportRect, e.Data.DataPointer, e.Data.SlicePitch, e.Data.RowPitch); writeableBitmap.AddDirtyRect(viewportRect); writeableBitmap.Unlock(); });