-
Notifications
You must be signed in to change notification settings - Fork 15
Revert "feat: 选区截图时保留屏幕笔迹" #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,6 @@ namespace Ink_Canvas | |
| { | ||
| public partial class MainWindow : Window | ||
| { | ||
| private bool _isAreaScreenshotInProgress; | ||
|
|
||
| /// <summary> | ||
| /// 在切页/加页场景下使用:先捕获当前画面到内存并克隆墨迹,然后立即返回;截图与墨迹保存在后台异步执行,不阻塞切页。 | ||
| /// 调用方应在调用本方法后立即执行 SaveStrokes、ClearStrokes、切页、RestoreStrokes 等逻辑。 | ||
|
|
@@ -159,98 +157,13 @@ internal void SaveScreenShotToDesktop() | |
| SaveInkCanvasStrokes(false); | ||
| } | ||
|
|
||
| private struct AnnotationSuspendState | ||
| { | ||
| public bool WasInAnnotationMode; | ||
| public int OriginalMode; | ||
| public System.Windows.Media.Brush OriginalFakeBackground; | ||
| public double OriginalFakeBackgroundOpacity; | ||
| public Visibility OriginalBackgroundCoverHolderVisibility; | ||
| public Visibility OriginalCanvasControlsVisibility; | ||
| public object OriginalHideInkCanvasContent; | ||
| } | ||
|
|
||
| private AnnotationSuspendState SuspendAnnotationForAreaScreenshotIfNeeded() | ||
| { | ||
| var state = new AnnotationSuspendState | ||
| { | ||
| WasInAnnotationMode = GridTransparencyFakeBackground.Background != System.Windows.Media.Brushes.Transparent, | ||
| OriginalMode = currentMode, | ||
| OriginalFakeBackground = GridTransparencyFakeBackground.Background, | ||
| OriginalFakeBackgroundOpacity = GridTransparencyFakeBackground.Opacity, | ||
| OriginalBackgroundCoverHolderVisibility = GridBackgroundCoverHolder.Visibility, | ||
| OriginalCanvasControlsVisibility = StackPanelCanvasControls.Visibility, | ||
| OriginalHideInkCanvasContent = BtnHideInkCanvas.Content | ||
| }; | ||
|
|
||
| if (!state.WasInAnnotationMode) | ||
| { | ||
| return state; | ||
| } | ||
|
|
||
| // 仅暂停批注视觉态,避免调用 BtnHideInkCanvas_Click 触发自动截图/上传及白板状态读写。 | ||
| GridTransparencyFakeBackground.Opacity = 0; | ||
| GridTransparencyFakeBackground.Background = System.Windows.Media.Brushes.Transparent; | ||
| GridBackgroundCoverHolder.Visibility = Visibility.Collapsed; | ||
| StackPanelCanvasControls.Visibility = Visibility.Collapsed; | ||
| CheckEnableTwoFingerGestureBtnVisibility(false); | ||
| HideSubPanels("cursor"); | ||
| BtnHideInkCanvas.Content = "显示\n画板"; | ||
|
|
||
| return state; | ||
| } | ||
|
|
||
| private void RestoreAnnotationAfterAreaScreenshot(AnnotationSuspendState state) | ||
| { | ||
| if (!state.WasInAnnotationMode || currentMode != state.OriginalMode) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| GridTransparencyFakeBackground.Opacity = state.OriginalFakeBackgroundOpacity; | ||
| GridTransparencyFakeBackground.Background = state.OriginalFakeBackground; | ||
| GridBackgroundCoverHolder.Visibility = state.OriginalBackgroundCoverHolderVisibility; | ||
| StackPanelCanvasControls.Visibility = state.OriginalCanvasControlsVisibility; | ||
| CheckEnableTwoFingerGestureBtnVisibility(state.OriginalCanvasControlsVisibility == Visibility.Visible); | ||
| BtnHideInkCanvas.Content = state.OriginalHideInkCanvasContent; | ||
| } | ||
|
|
||
| internal async Task SaveAreaScreenShotToDesktop() | ||
| { | ||
| if (_isAreaScreenshotInProgress) | ||
| { | ||
| ShowNotification("截图进行中,请先完成当前截图"); | ||
| return; | ||
| } | ||
|
|
||
| _isAreaScreenshotInProgress = true; | ||
|
|
||
| var annotationState = SuspendAnnotationForAreaScreenshotIfNeeded(); | ||
| var originalFloatingBarVisibility = ViewboxFloatingBar.Visibility; | ||
| var shouldRestoreFloatingBarVisibility = true; | ||
| var originalVisibility = Visibility; | ||
| try | ||
| { | ||
| if (annotationState.WasInAnnotationMode) | ||
| { | ||
| // 等待一次 UI 刷新,确保批注暂停状态已完成。 | ||
| await System.Windows.Threading.Dispatcher.Yield(System.Windows.Threading.DispatcherPriority.Render); | ||
| } | ||
|
|
||
| // 从浮动栏触发选区截图时,临时隐藏浮动栏,避免遮挡选区与误入截图。 | ||
| if (originalFloatingBarVisibility == Visibility.Visible) | ||
| { | ||
| ViewboxFloatingBar.Visibility = Visibility.Collapsed; | ||
| await System.Windows.Threading.Dispatcher.Yield(System.Windows.Threading.DispatcherPriority.Render); | ||
| } | ||
|
|
||
| // 选区截图时确保墨迹层可见,避免从浮动栏触发时出现“先隐藏再截图”。 | ||
| if (inkCanvas.Visibility != Visibility.Visible) | ||
| { | ||
| inkCanvas.Visibility = Visibility.Visible; | ||
| } | ||
|
|
||
| // 等待一次 UI 刷新,确保可见性状态已生效。 | ||
| await System.Windows.Threading.Dispatcher.Yield(System.Windows.Threading.DispatcherPriority.Render); | ||
| Visibility = Visibility.Hidden; | ||
| await Task.Delay(200); | ||
|
|
||
| var screenshotResult = await ShowScreenshotSelector(); | ||
|
|
||
|
|
@@ -262,12 +175,7 @@ internal async Task SaveAreaScreenShotToDesktop() | |
|
|
||
| if (screenshotResult.Value.AddToWhiteboard) | ||
| { | ||
| // 仅在白板接管流程已确认完成时,才跳过本方法对浮动栏可见性的恢复。 | ||
| var whiteboardHandoffCompleted = await AddScreenshotToNewWhiteboardPage(screenshotResult.Value); | ||
| if (whiteboardHandoffCompleted) | ||
| { | ||
| shouldRestoreFloatingBarVisibility = false; | ||
| } | ||
| await AddScreenshotToNewWhiteboardPage(screenshotResult.Value); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -281,7 +189,7 @@ internal async Task SaveAreaScreenShotToDesktop() | |
| Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), | ||
| $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.png"); | ||
|
|
||
| using (var originalBitmap = CaptureScreenAreaWithOptionalInk(screenshotResult.Value.Area, screenshotResult.Value.IncludeInk)) | ||
| using (var originalBitmap = CaptureScreenArea(screenshotResult.Value.Area)) | ||
| { | ||
| if (originalBitmap == null) | ||
| { | ||
|
|
@@ -327,16 +235,11 @@ internal async Task SaveAreaScreenShotToDesktop() | |
| } | ||
| finally | ||
| { | ||
| _isAreaScreenshotInProgress = false; | ||
| if (shouldRestoreFloatingBarVisibility) | ||
| { | ||
| ViewboxFloatingBar.Visibility = originalFloatingBarVisibility; | ||
| } | ||
| RestoreAnnotationAfterAreaScreenshot(annotationState); | ||
| Visibility = originalVisibility; | ||
| } | ||
| } | ||
|
|
||
| private async Task<bool> AddScreenshotToNewWhiteboardPage(ScreenshotResult screenshotResult) | ||
| private async Task AddScreenshotToNewWhiteboardPage(ScreenshotResult screenshotResult) | ||
| { | ||
| // 先在当前场景准备截图数据,再进白板,避免误截到白板页面 | ||
| BitmapSource bitmapSourceForClipboard = null; | ||
|
|
@@ -356,15 +259,15 @@ private async Task<bool> AddScreenshotToNewWhiteboardPage(ScreenshotResult scree | |
| if (screenshotResult.Area.Width <= 0 || screenshotResult.Area.Height <= 0) | ||
| { | ||
| ShowNotification("未选择有效截图区域"); | ||
| return false; | ||
| return; | ||
| } | ||
|
|
||
| using (var originalBitmap = CaptureScreenAreaWithOptionalInk(screenshotResult.Area, screenshotResult.IncludeInk)) | ||
| using (var originalBitmap = CaptureScreenArea(screenshotResult.Area)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| { | ||
| if (originalBitmap == null) | ||
| { | ||
| ShowNotification("截图失败"); | ||
| return false; | ||
| return; | ||
| } | ||
|
|
||
| Bitmap finalBitmap = originalBitmap; | ||
|
|
@@ -393,7 +296,7 @@ private async Task<bool> AddScreenshotToNewWhiteboardPage(ScreenshotResult scree | |
| if (bitmapSourceForClipboard == null) | ||
| { | ||
| ShowNotification("截图转换失败"); | ||
| return false; | ||
| return; | ||
| } | ||
|
|
||
| // 图像已拷贝到内存后再进入白板 | ||
|
|
@@ -408,7 +311,6 @@ private async Task<bool> AddScreenshotToNewWhiteboardPage(ScreenshotResult scree | |
| BtnWhiteBoardAdd_Click(null, EventArgs.Empty); | ||
|
|
||
| await InsertBitmapSourceToCanvas(bitmapSourceForClipboard); | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
CaptureScreenshotAndInsert, the capture call was switched toCaptureScreenArea(...), but this method no longer hides the main window before grabbing pixels. Because the window is restored immediately after selector close (before this call), the app chrome/toolbar/ink overlay can be captured into the inserted screenshot when it overlaps the selected region. This regresses the documented behavior of avoiding self-capture in the insert workflow.Useful? React with 👍 / 👎.