/// <summary> /// Called once per frame, generates images /// </summary> private void DrawFrameToScreen(uint[] frame) { if (CycleAnimations) { tickCount++; var timeMs = AnimationLength; // ms per animation if ((tickCount % (timeMs / FramesPerSecond)) == 0) { Next(); } } // ensure the screen bitmap is the right size and format var h = DemoManager.Height; var w = DemoManager.Width; var img = ImageSource; if (img == null) { img = new WriteableBitmap(w, h, 96.0, 96.0, PixelFormats.Bgra32, null); } var bmp = img as WriteableBitmap; if (bmp == null) { return; // something wrong, return } if (bmp.PixelWidth != w || bmp.PixelHeight != h) { bmp = new WriteableBitmap(w, h, 96.0, 96.0, PixelFormats.Bgra32, null); } bmp.WritePixels(new Int32Rect(0, 0, w, h), frame, w * 4, 0); ActualFramesPerSecond = fps.Tick(); ImageSource = null; // toggle update ImageSource = bmp; if (SaveImages) { SaveImage(bmp, ImagePlayback.Filename(filePath, imageCount++)); } }