private async System.Threading.Tasks.Task SendFrame(byte[] frame) { // create a new BitmapImage from the JPEG bytes BitmapSource bitmap = await WpfUtilities.LoadImageAsync(new MemoryStream(frame)); // tell whoever's listening that we have a frame to draw if (FrameReady != null) { FrameReady(this, new FrameReadyEventArgs { FrameBuffer = frame, BitmapSource = bitmap }); } }
private async void SaveFrame(BitmapSource bitmapSource) { try { string fileName = "snap" + imageIndex++ + ".png"; var store = DataStore.Instance; var folder = store.SnapshotFolder; var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { await WpfUtilities.SaveImageAsync(bitmapSource, fileStream); } } catch (Exception ex) { Debug.WriteLine("Error saving frame: " + ex.Message); } }