-
Notifications
You must be signed in to change notification settings - Fork 255
ScreenCapture
闫驚鏵(Jinhua Yan) edited this page Nov 24, 2024
·
7 revisions
var screenCaptureExt = new ScreenCaptureExt();
screenCaptureExt.SnapCanceled += ScreenCaptureExt_SnapCanceled;
screenCaptureExt.SnapCompleted += ScreenCaptureExt_SnapCompleted;
private void ScreenCaptureExt_SnapCompleted(System.Windows.Media.Imaging.BitmapSource bitmap)
{
//Completed
}
private void ScreenCaptureExt_SnapCanceled()
{
//Canceled
}
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
}
<Window
x:Class="WpfScreenCapture.ScreenCaptureWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfScreenCapture"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wd="https://github.com/WPFDevelopersOrg/WPFDevelopers"
Title="Window1"
Width="800"
Height="450"
mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
<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>
</ResourceDictionary>
</Window.Resources>
<Button
Margin="0,10"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Click="Button_Click"
Content="ScreenCapture" />
</Window>
private void Button_Click(object sender, RoutedEventArgs e)
{
Dispatcher.Invoke(new Action(delegate
{
ScreenCapture screenCapturer = new ScreenCapture(resources: this.Resources);
screenCapturer.Capture();
}));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ScreenCaptureExt screenCaptureExt = new ScreenCaptureExt();
screenCaptureExt.SnapCanceled += ScreenCaptureExt_SnapCanceled;
screenCaptureExt.SnapCompleted += ScreenCaptureExt_SnapCompleted;
}