/// <summary> /// Initializes a new instance of the <see cref="ColorFrameBitmap" /> class /// suitable for displaying the supplied <see cref="ReplayColorFrame" />. /// </summary> /// <param name="frame">The frame.</param> public ColorFrameBitmap(ReplayColorFrame frame) { #if NETFX_CORE _bitmap = BitmapFactory.New(frame.Width, frame.Height); _bytes = new byte[_bitmap.PixelWidth * _bitmap.PixelHeight * 4]; _stream = _bitmap.PixelBuffer.AsStream(); #else // force population of PixelFormat var data = frame.GetFrameDataAsync().Result; _bitmap = new WriteableBitmap(frame.Width, frame.Height, 96, 96, frame.Codec.PixelFormat, null); _bytes = new byte[_bitmap.PixelWidth * _bitmap.PixelHeight * (_bitmap.Format.BitsPerPixel / 8)]; _dirtyRect = new Int32Rect(0, 0, frame.Width, frame.Height); #endif }
/// <summary> /// Update the Bitmap from the supplied <c>ReplayColorFrame</c>. /// </summary> public void Update(ReplayColorFrame frame) { if (frame != null) { frame.GetFrameDataAsync().ContinueWith(async(pixels) => { #if NETFX_CORE await _bitmap.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { _stream.Seek(0, SeekOrigin.Begin); _stream.Write(pixels.Result, 0, pixels.Result.Length); _bitmap.Invalidate(); }); #else await _bitmap.Dispatcher.InvokeAsync(() => { _bitmap.FromByteArray(pixels.Result); }); #endif }); } }