ScreenToGif项目由四个文件夹组成:
- Files 存放协议文件
- GifRecorder 存放gif编码器代码
- ScreenToGif 存放主代码
- Other 存放Hooktest和Translator的代码
问题1:GifRecorder 和ScreenToGif、Hooktest、Translator 下面都有了一个Properties,里面有个AssemblyInfo.cs是什么东西?
.net工程的Properties文件夹下自动生成一个名为AssemblyInfo.cs的文件,一般情况下我们很少直接改动该文件。但我们实际上通过另一个形式操作该文件。那就是通过在鼠标右键点击项目的属性进入“应用程序”->“程序集信息”,然后修改信息。
程序集指的是DLL或者EXE等可执行文件。
问题2:启动界面分析
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:n="clr-namespace:ScreenToGif.Controls" xmlns:u="clr-namespace:ScreenToGif.Util" Title="{DynamicResource Title.StartUp}" Height="220" Width="500" Icon="/Resources/Logo.ico" WindowStartupLocation="CenterScreen" MinWidth="500" MinHeight="220" UseLayoutRounding="True" Loaded="Startup_OnLoaded"> Margin="5" Style="{StaticResource Style.Button.Horizontal}" Effect="{StaticResource Shadow.Black.Small}" Padding="2" MaxSize="25" Command="u:Commands.Options"/> Effect="{StaticResource Shadow.Black.Tiny}" MaxSize="36" Content="{StaticResource Vector.Record.New}" Command="u:Commands.NewRecording" Style="{StaticResource Style.Button.Vertical.Border}" FontSize="13"> MaxWidth="250" Placement="Bottom" HorizontalOffset="-5"/> Effect="{StaticResource Shadow.Black.Tiny}" MaxSize="36" Content="{StaticResource Vector.Camera.New}" Command="u:Commands.NewWebcamRecording" Style="{StaticResource Style.Button.Vertical.Border}" FontSize="13"> Effect="{StaticResource Shadow.Black.Tiny}" MaxSize="36" Content="{StaticResource Vector.Board.New}" Command="u:Commands.NewBoardRecording" Style="{StaticResource Style.Button.Vertical.Border}" FontSize="13"> Effect="{StaticResource Shadow.Black.Tiny}" MaxSize="35" Content="{StaticResource Vector.Editor}" Command="u:Commands.Editor" Style="{StaticResource Style.Button.Vertical.Border}" FontSize="13"> 我是一个资源 string text = (string) this.FindResource(“str”)//资源中的文件要自己来进行格式转换 使用标签引用和程序中的FindResource引用会在当前控件的Resource属性中查找,如果找不到,就会找上一级的。 如果得知就是引用当前的,可以使用string text = (string) this.Resources[“str”] 静态资源和动态资源中的静态和动态不是描述资源的,描述控件行为的,也说明改资源项是否可以被外部改写(类似xml的改写),只载入一次,之后永远不变,还是可以动态的变化。 对于动态资源可以使用this.Resoures[“res2”]=new TextBlock(){text=”我要改变了”} ,静态资源不理会对资源的重新赋值 比如在ScreenToGif这个项目中,有个Windows文件夹,下面有个Other文件,里面有个ColorSelector.xaml,如何在其他界面文件中使用呢? 步骤: var colorPicker = new ColorSelector(UserSettings.All.BoardColor) { Owner = this }; var result = colorPicker.ShowDialog(); http://blog.csdn.net/aoshilang2249/article/details/45129365 《深入浅出WPF》 深入浅出话模板 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:n="clr-namespace:ScreenToGif.Controls" xmlns:u="clr-namespace:ScreenToGif.Util" xmlns:c="clr-namespace:ScreenToGif.Util.Converters" Title="ScreenToGif" SnapsToDevicePixels="True" UseLayoutRounding="True" AllowsTransparency="True" WindowStyle="None" Topmost="True" Icon="../Resources/Logo.ico" Child="{StaticResource Vector.Back}" IsThin="{Binding RecorderThinMode, Source={x:Static u:UserSettings.All}}" IsFullScreen="{Binding FullScreenMode, Source={x:Static u:UserSettings.All}}" Width="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderWidth, Mode=TwoWay}" Height="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderHeight, Mode=TwoWay}" Left="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderLeft, Mode=TwoWay}" Top="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderTop, Mode=TwoWay}" FocusManager.FocusedElement="{Binding RelativeSource={x:Static RelativeSource.Self}, Mode=OneTime}" Foreground="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderForeground, Mode=TwoWay, Converter={StaticResource ColorToBrush}}" Background="{Binding Source={x:Static u:UserSettings.All}, Path=RecorderBackground, Mode=TwoWay, Converter={StaticResource ColorToBrush}}" SizeChanged="LightWindow_SizeChanged" Loaded="Recorder_Loaded" Closing="Window_Closing" LocationChanged="Window_LocationChanged"> From="{Binding ElementName=DiscardButton,Path=Opacity}" To="0" Duration="0:0:1"> KeyboardNavigation.TabNavigation="Cycle" MouseLeftButtonDown="CommandGrid_MouseLeftButtonDown"> ContentHeight="14" Padding="4,1" TabIndex="0" Click="BackButton_Click"/> ContentHeight="10" Padding="4,1" TabIndex="1" Click="CloseButton_Click"/> FontWeight="Regular" Margin="5,0,0,0" Foreground="#FF6F5252" Effect="{DynamicResource Shadow.Foreground.Small}"/> FontFamily="Segoe UI" FontSize="12" FontWeight="Regular" Margin="5,0,0,0" Foreground="#FF061E87" Effect="{DynamicResource Shadow.Foreground.Small}"/> ScrollViewer.VerticalScrollBarVisibility="Disabled"> HorizontalContentAlignment="Center" Effect="{StaticResource Shadow.Foreground.Small}" ContentHeight="20" ContentWidth="20" Visibility="{Binding FullScreenMode, Source={x:Static u:UserSettings.All}, Converter={StaticResource InvertedBoolToVisibility}}" Command="u:Commands.EnableSnapToWindow" Padding="3" TabIndex="2" PreviewMouseDown="SnapButton_PreviewMouseDown"> Effect="{StaticResource Shadow.Foreground.Small}" ContentHeight="20" ContentWidth="20" Command="u:Commands.Options" Padding="3" TabIndex="3"> IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="24" IsTabStop="False"/> IsInverted="True" Minimum="1" Maximum="60" SegmentColor="#FFE28A73" Radius="10" IsTabStop="False"/> Value="{Binding Source={x:Static u:UserSettings.All}, Path=LatestFps, Mode=TwoWay}" Visibility="{Binding SnapshotMode, Source={x:Static u:UserSettings.All}, Converter={StaticResource InvertedBoolToVisibility}}"> 启动界面,是4个选项,录制桌面、录制摄像头、录制绘图、视频帧编辑器 录制桌面、录制摄像头、录制绘图其实是一样的东西。 C:\Users\laiqun\AppData\Local\Temp\ C:\Users\laiqun\AppData\Local\Temp\ScreenToGif\Recording\2018-02-03 14-18-53 Text="{Binding Stage, ElementName=RecorderLightWindow, Converter={StaticResource StageToButtonStringConverter}, FallbackValue={StaticResource Recorder.Record}}" Content="{Binding Stage, ElementName=RecorderLightWindow, Converter={StaticResource StageToCanvasConverter}, FallbackValue={StaticResource Vector.Record}}" Click="RecordPauseButton_Click" Style="{StaticResource Style.Button.Horizontal}" Foreground="{Binding ElementName=RecorderLightWindow, Path=Foreground}" MinWidth="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}" 录制按钮点击 private void RecordPauseButton_Click(object sender, RoutedEventArgs e) { if (!UserSettings.All.SnapshotMode) RecordPause(); else Snap(); } RecordPause函数的实现: private async void RecordPause() { switch (Stage) //Stage在哪儿改变? { case Stage.Stopped: //一开始肯定是从stopped 状态开始的,启动录制后,这里会将stopped状态改变为recording,表示正在录制。 录制其实在启动一个定时器,做各种记录性的操作。 从UnregisterEvents这个函数可以看出蛛丝马迹 private void UnregisterEvents() { _capture.Tick -= Normal_Elapsed; _capture.Tick -= NormalAsync_Elapsed; _capture.Tick -= Cursor_Elapsed; _capture.Tick -= CursorAsync_Elapsed; _capture.Tick -= FullCursor_Elapsed; _capture.Tick -= Full_Elapsed; } private void Normal_Elapsed(object sender, EventArgs e) { //Actual position on the screen. 获取要录制的区域 var lefttop = Dispatcher.Invoke(() => { var left = Math.Round((Math.Round(Left, MidpointRounding.AwayFromZero) + Constants.LeftOffset) * _scale); var top = Math.Round((Math.Round(Top, MidpointRounding.AwayFromZero) + Constants.TopOffset) * _scale); return new Point((int)left, (int)top); }); //Take a screenshot of the area. var bt = Native.Capture(_size, lefttop.X, lefttop.Y); if (bt == null || !IsLoaded) return; var fileName = $"{Project.FullPath}{FrameCount}.png"; //这里只是简单的更新一下图像文件信息,并没有实际创建图像文件 Project.Frames.Add(new FrameInfo(fileName, FrameRate.GetMilliseconds(_snapDelay), new List _keyList.Clear(); //AddFrames创建图像文件 ThreadPool.QueueUserWorkItem(delegate { AddFrames(fileName, new Bitmap(bt)); });//线程池 FrameCount++; } 1. System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();//实例化 2. myTimer.Tick += new EventHandler(函数名); //给timer挂起事件 3. myTimer.Enabled = true;//使timer可用 4. myTimer.Interval = n; //设置时间间隔,以毫秒为单位 5. myTimer.Stop(); //如果要暂停计时则使用Stop()方法 6. myTimer.Enabled = false;//若要停止使用timer,则使之不可用 是一个xml文件,用来读取和写入配置的。 程序的相关地方会读取这些配置,为了方便,最好把读取配置项的地方写在一起.这部分的代码在呢?UserSettings namespace ScreenToGif.Util { internal sealed class UserSettings : INotifyPropertyChanged { #region Variables private static ResourceDictionary _local; private static ResourceDictionary _appData; private static readonly ResourceDictionary Default; public event PropertyChangedEventHandler PropertyChanged; public static UserSettings All { get; } = new UserSettings(); 视频帧编辑器负责把录制的一帧帧的图像载入,创建对应的缩略图。这部分的代码在呢? 我想在录制的时候顺势把鼠标和键盘录制进去,怎么实现?这部分的代码在呢? Recorder构造函数 _actHook = new UserActivityHook(true, true); //true for the mouse, true for the keyboard. _actHook.KeyDown += KeyHookTarget; _actHook.OnMouseActivity += MouseHookTarget; 这是在xaml中引用,如何在程序中引用呢?
将资源程序写到外部文件,如何在程序中引用?
问题4:一个界面文件,是如何调用另外一个界面文件的?
问题5: style属性是什么东西?
问题6:录制屏幕界面分析
问题7:如果这个软件让你实现,你会怎么做?
无非是设置一个定时器,定时的采集图像放到硬盘中。这部分的代码在呢?
设置项界面