private void Draw(int width, int height, int currentFrame) { try { var image = imageLogic.Draw(width, height, recorderLogic.Records, currentFrame); if (image != null) { Dispatcher.Invoke(() => { try { var bmp = new WriteableBitmap(image.Width, image.Height, image.Metadata.HorizontalResolution, image.Metadata.VerticalResolution, PixelFormats.Bgra32, null); bmp.Lock(); try { var backBuffer = bmp.BackBuffer; for (var y = 0; y < image.Height; y++) { var buffer = image.GetPixelRowSpan(y); for (var x = 0; x < image.Width; x++) { var backBufferPos = backBuffer + (y * image.Width + x) * 4; var rgba = buffer[x]; var color = rgba.A << 24 | rgba.R << 16 | rgba.G << 8 | rgba.B; Marshal.WriteInt32(backBufferPos, color); } } bmp.AddDirtyRect(new Int32Rect(0, 0, image.Width, image.Height)); } finally { bmp.Unlock(); ImageChart.Source = bmp; } } catch (Exception ex) { #if DEBUG logger.LogError(ex, "Cannot convert to WriteableBitmap"); #endif } finally { image.Dispose(); } }); } } catch (Exception ex) { #if DEBUG logger.LogError(ex, "Cannot draw"); #endif } }