RenderTargetBitmap RenderFrame(int frameNumber, TimeSpan pts, double duration, Noise noise, Fade fade) { if (_mode == RenderMode.MontyPython) { var buffer = new RenderTargetBitmap(7680, 4320, 384.0, 384.0, PixelFormats.Pbgra32); var visual = ComposeVisual(pts, duration); visual.SnapsToDevicePixels = false; visual = noise.ApplyTo(visual); visual = fade.ApplyTo(frameNumber, visual); visual.Measure(new Size(1920, 1080)); visual.Arrange(new Rect(0, 0, 1920, 1080)); buffer.Render(visual); var bufferElement = new ImageDrawing(buffer, new Rect(0, 0, 1920, 1080)); var bufferVisual = new DrawingVisual(); RenderOptions.SetBitmapScalingMode(bufferElement, BitmapScalingMode.HighQuality); using (var context = bufferVisual.RenderOpen()) context.DrawDrawing(bufferElement); var target = new RenderTargetBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32); target.Render(bufferVisual); return(target); } else { var target = new RenderTargetBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32); var visual = ComposeVisual(pts, duration); visual = noise.ApplyTo(visual); visual = fade.ApplyTo(frameNumber, visual); visual.Measure(new Size(1920, 1080)); visual.Arrange(new Rect(0, 0, 1920, 1080)); target.Render(visual); return(target); } }