Skip to content

ScreenCapture

闫驚鏵(Jinhua Yan) edited this page Dec 2, 2023 · 7 revisions

CSharp

Application.Current.Dispatcher.Invoke(new Action(delegate
{
    var screenCapturer = new ScreenCapture();
    screenCapturer.SnapCompleted += ScreenCapturer_SnapCompleted;
    screenCapturer.SnapCanceled += ScreenCapturer_SnapCanceled;
    screenCapturer.Capture();
}));
 private void ScreenCapturer_SnapCanceled()
 {
    //Canceled
 }

private void ScreenCapturer_SnapCompleted(CroppedBitmap bitmap)
{
   //Completed
}

When the loaded resource dictionary cannot be written in App.xaml, ScreenCapture and ScreenCut cannot be used normally when written in Window.Resources.

Introduce resources to the current page

<Window.Resources>
       <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary Source="pack://application:,,,/WPFDevelopers;component/Themes/Light.Blue.xaml"/>
           <!--需要注意 wd:Resources 必须在配色主题后,Theme="Dark" 为黑色皮肤-->
           <wd:Resources Theme="Light"/>
           <ResourceDictionary Source="pack://application:,,,/WPFDevelopers;component/Themes/Theme.xaml"/>
       </ResourceDictionary.MergedDictionaries>
</Window.Resources>

Send its own Resources when showing the ScreenCapture control.

 Dispatcher.Invoke(new Action(delegate
 {
    ScreenCapture screenCapturer = new ScreenCapture(resources: this.Resources);
    screenCapturer.Capture();
 }));
Clone this wiki locally