/// <summary> /// Call back function for take snapshot command dependency property, /// when no video device source selected show appropriate message /// or message currently display in user-control based on user input. /// </summary> /// <exception cref="InvalidOperationException">Wraps and throws <see cref="InvalidOperationException"/> when any exception is thrown from this method.</exception> public void TakeSnapshotCallback() { try { var playerPoint = new System.Drawing.Point(); //// Get the position of the source video device player. if (string.IsNullOrWhiteSpace(VideoSourceId)) { var noVideoDeviceSourcePoint = NoVideoSourceGrid.PointToScreen(new Point(0, 0)); playerPoint.X = (int)noVideoDeviceSourcePoint.X; playerPoint.Y = (int)noVideoDeviceSourcePoint.Y; } else { playerPoint = VideoSourcePlayer.PointToScreen(new System.Drawing.Point(VideoSourcePlayer.ClientRectangle.X, VideoSourcePlayer.ClientRectangle.Y)); } if (double.IsNaN(VideoPreviewWidth) || double.IsNaN(VideoPreviewHeight)) { using ( var bitmap = new Bitmap((int)VideoSourceWindowsFormsHost.ActualWidth, (int)VideoSourceWindowsFormsHost.ActualHeight)) { using (var graphicsFromImage = Graphics.FromImage(bitmap)) { graphicsFromImage.CopyFromScreen(playerPoint, System.Drawing.Point.Empty, new System.Drawing.Size((int)VideoSourceWindowsFormsHost.ActualWidth, (int)VideoSourceWindowsFormsHost.ActualHeight)); } SnapshotBitmap = new Bitmap(bitmap); } } else { using (var bitmap = new Bitmap((int)VideoPreviewWidth, (int)VideoPreviewHeight)) { using (var graphicsFromImage = Graphics.FromImage(bitmap)) { graphicsFromImage.CopyFromScreen(playerPoint, System.Drawing.Point.Empty, new System.Drawing.Size((int)VideoPreviewWidth, (int)VideoPreviewHeight)); } SnapshotBitmap = new Bitmap(bitmap); } } } catch (Exception exception) { throw new InvalidOperationException( "Error occurred while trying to take snapshot from currently selected source video device", exception); } }