Click or drag to resize
AB4D logo

DXSceneRenderToBitmap(Int32, Int32, Int32, BackBufferReadyEventHandler) Method

RenderToBitmap renders the 3D scene to bitmap with specified width, height and multisampling count (used if possible). When the scene is rendered the renderedTextureReadyCallback delegate is called - here it is possible to read the memory with the rendered buffer.

Namespace: Ab3d.DirectX
Assembly: Ab3d.DXEngine (in Ab3d.DXEngine.dll) Version: 7.1.9105.2048 (1.0.0.0)
Syntax
C#
public void RenderToBitmap(
	int width,
	int height,
	int preferedMultisampling,
	BackBufferReadyEventHandler renderedTextureReadyCallback
)

Parameters

width  Int32
width of the rendered bitmap
height  Int32
height of the rendered bitmap
preferedMultisampling  Int32
multisampling count that is used to render the image (used if possible)
renderedTextureReadyCallback  BackBufferReadyEventHandler
Delegate that is called when the scene is rendered. In this delegate it is possible to read the memory with the rendered buffer.
Example

The following code uses RenderToBitmap to render to WPF's WriteableBitmap:

C#
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();
});
See Also