RenderToBitmap poor performance

RenderToBitmap takes a long time (~60 seconds consistently) to render a 2048x2048 image. This seems excessive as in the onscreen view I can render in realtime. 

Is this expected behaviour? If so, are there any workarounds for it?

I'm calling this routine:
public RenderTargetBitmap RenderToBitmap(Brush backgroundBrush = null, int dpi = 96);

     var viewport3D = new Viewport3D();

     viewport3D.Width = 2048;
     viewport3D.Height = 2048;

     var camera = new FirstPersonCamera();
     camera.Position = new Point3D(0, 0, 0);
     camera.Bank = 0;
     camera.Heading = 0;
     camera.Attitude = -90;
     camera.FieldOfView = 92;
     camera.TargetViewport3D = viewport3D;

     var displayModels = objs.AsModel3DGroup();

     foreach (var m in objs.Values)


     Stopwatch renderStopWatch = new Stopwatch();

     var img = camera.RenderToBitmap(backgroundBrush);    

camera.RenderToBitmap method is using WPF's RenderTargetBitmap to render the 3D scene to a bitmap.  RenderTargetBitmap may use software rendering for this. This is also probably why it takes much longer than when the 3D scene is shown on the screen - there hardware rendering is used. This is pure WPF code so I cannot do much to improve performance.

If want better performance, then you will need to use use Ab3d.DXEngine. It uses a super fast DirectX 11 rendering engine that can render 3D scene that is defined by WPF 3D and Ab3d.PowerToys objects - so you do not need to change the code that defines your scene. With Ab3d.DXEngine you will be able to call DXViewportView.RenderToBitmap that is fully hardware accelerated and will work as fast as when shown on the screen. Ab3d.DXEngine also provides significantly improved visuals. See samples here:
Andrej Benedik
Thanks for the prompt response. 

Apologies if not clear in the previous message, but it's an offscreen render.

I have my on screen render with directx - which would explain why that is fast.

Can the offscreen render be wrapped with directx too?
Yes, just call DXViewportView.RenderToBitmap instead of camera.RenderToBitmap - the later will use WPF's rendering.
Andrej Benedik
Looks like it works perfectly, thank you!  (60seconds down to 0.1seconds).


Forum Jump:

Users browsing this thread:
1 Guest(s)