C# WPF GIF Capture 大漠插件调用实例
By
jerryxjr1220
at 2023-11-10 • 0人收藏 • 332人看过
<hc:GlowWindow x:Class="WPFGIFCapture.Views.MainWindow" 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:WPFGIFCapture.ViewModels" xmlns:hc="https://handyorg.github.io/handycontrol" d:DataContext="{d:DesignInstance Type=vm:MainViewModel}" mc:Ignorable="d" MinWidth="500" MinHeight="200" Title="MainWindow" Height="500" Width="500" ResizeMode="CanResize" FontFamily="JetBrains Mono" Background="Transparent" FontSize="{StaticResource TextFontSize}" WindowStyle="None" AllowsTransparency="True"> <Window.Resources> </Window.Resources> <hc:SimplePanel> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Border Grid.Row="0" Background="White" MinWidth="400" MinHeight="30" MouseDown="UIElement_OnMouseDown"> <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Center"> <TextBlock Text="GIF Capture" Style="{StaticResource TextBlockDefaultPrimary}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" /> <Button hc:IconElement.Geometry="{StaticResource SaveGeometry}" Style="{StaticResource ButtonDashedPrimary}" Margin="10,0" x:Name="ButtonSave" IsEnabled="True" Click="ButtonSave_OnClick" /> <Button hc:IconElement.Geometry="{StaticResource RightGeometry}" Style="{StaticResource ButtonDashedPrimary}" Margin="10,0" x:Name="ButtonCapture" IsEnabled="False" Click="ButtonCapture_OnClick" /> <TextBlock Text="TimeSpan" Style="{StaticResource TextBlockDefaultPrimary}" /> <Slider Width="150" Style="{StaticResource SliderBaseStyle}" Minimum="2" Maximum="30" Value="{Binding Timespan, Mode=TwoWay}" /> <TextBlock Width="30" Text="{Binding Timespan, StringFormat={}{0:F1}}" Style="{StaticResource TextBlockDefaultPrimary}" /> <Button hc:IconElement.Geometry="{StaticResource CloseGeometry}" Style="{StaticResource ButtonDanger}" Margin="10,0" Click="ButtonBase_OnClick" /> </WrapPanel> </Border> <Border Grid.Row="1" x:Name="BorderCapture" BorderBrush="{StaticResource PrimaryBrush}" BorderThickness="2" /> </Grid> </hc:SimplePanel> </hc:GlowWindow>
using CommunityToolkit.Mvvm.ComponentModel; using Liuliu.ScriptEngine; namespace WPFGIFCapture.Models; public partial class DamoClass : ObservableObject { [ObservableProperty] private DmPlugin _damo; public DamoClass(string path) { Damo = new DmPlugin(path); } }
using CommunityToolkit.Mvvm.ComponentModel; using WPFGIFCapture.Models; namespace WPFGIFCapture.ViewModels; public partial class MainViewModel : ObservableObject { [ObservableProperty] private DamoClass _damoSoft; [ObservableProperty] private string _gifPath; [ObservableProperty] private double _timespan; public MainViewModel() { DamoSoft = new DamoClass("./libs/dm-3.1233.dll"); Timespan = 5; } public void GifCapture(int x1, int y1, int x2, int y2) { DamoSoft.Damo.CaptureGif(x1, y1, x2, y2, GifPath, 50, (int)Timespan * 1000); } }
using System.Windows; using System.Windows.Input; using HandyControl.Controls; using Microsoft.Win32; using WPFGIFCapture.ViewModels; namespace WPFGIFCapture.Views; /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : GlowWindow { private readonly MainViewModel mainViewModel; public MainWindow() { InitializeComponent(); mainViewModel = new MainViewModel(); DataContext = mainViewModel; } private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } private void ButtonSave_OnClick(object sender, RoutedEventArgs e) { var fd = new SaveFileDialog(); fd.Filter = "GIF (*.gif)|*.gif"; if (fd.ShowDialog() == true) { mainViewModel.GifPath = fd.FileName; ButtonCapture.IsEnabled = true; ButtonSave.IsEnabled = false; } } private void ButtonCapture_OnClick(object sender, RoutedEventArgs e) { ButtonCapture.IsEnabled = false; mainViewModel.GifCapture((int)Left, (int)Top + 31, (int)Left + (int)Width, (int)Top + (int)Height); ButtonSave.IsEnabled = true; } }
登录后方可回帖