├── .gitattributes ├── .gitignore ├── ComeCapture.sln ├── ComeCapture ├── App.config ├── App.xaml ├── App.xaml.cs ├── ComeCapture.csproj ├── Controls │ ├── ArrowTool.cs │ ├── EllipseTool.cs │ ├── ImageEditBar.cs │ ├── KeyboardTextBox.cs │ ├── LineTool.cs │ ├── MainImage.cs │ ├── RectangleTool.cs │ ├── SizeColorBar.cs │ ├── TextBoxControl.cs │ ├── TextTool.cs │ ├── ToolButton.cs │ └── ZoomThumb.cs ├── Converters │ ├── ColorConverter.cs │ ├── SizeConverter.cs │ └── ToolConverter.cs ├── Helpers │ ├── ImageHelper.cs │ ├── RelayCommand.cs │ ├── ScreenHelper.cs │ └── WpfHelper.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Models │ ├── AppModel.cs │ ├── Direction.cs │ ├── EntityBase.cs │ ├── Limit.cs │ └── Tool.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── cut.ico │ ├── showyou.png │ ├── 保存.png │ ├── 后退.png │ ├── 笔刷.png │ ├── 箭头.png │ └── 设置.png ├── Themes │ └── Generic.xaml └── cut.ico └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /ComeCapture.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComeCapture", "ComeCapture\ComeCapture.csproj", "{E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {B018D4C9-A923-4E9A-B585-D95751BE7231} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ComeCapture/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ComeCapture/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ComeCapture/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace ComeCapture 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ComeCapture/ComeCapture.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E1DF0DCA-D261-4F81-9F64-389B3CFCAE2F} 8 | WinExe 9 | ComeCapture 10 | ComeCapture 11 | v4.6.1 12 | 512 13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 4 15 | true 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | cut.ico 38 | 39 | 40 | 41 | true 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 4.0 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | MSBuild:Compile 64 | Designer 65 | 66 | 67 | App.xaml 68 | Code 69 | 70 | 71 | 72 | MainWindow.xaml 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | Code 102 | 103 | 104 | True 105 | Settings.settings 106 | True 107 | 108 | 109 | SettingsSingleFileGenerator 110 | Settings.Designer.cs 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | MSBuild:Compile 126 | Designer 127 | 128 | 129 | MSBuild:Compile 130 | Designer 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /ComeCapture/Controls/ArrowTool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Media; 6 | 7 | namespace ComeCapture.Controls 8 | { 9 | public class ArrowTool : StackPanel 10 | { 11 | private StreamGeometry geometry = new StreamGeometry(); 12 | 13 | static ArrowTool() 14 | { 15 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowTool), new FrameworkPropertyMetadata(typeof(ArrowTool))); 16 | } 17 | 18 | public ArrowTool() 19 | { 20 | _Current = this; 21 | } 22 | 23 | public List CreateArrow(Point start, Point end) 24 | { 25 | var tan = Math.Atan((end.Y - start.Y) / (end.X - start.X)); 26 | var Move0 = tan - ArrowAngle; 27 | var Move1 = tan + ArrowAngle; 28 | var convert = end.X > start.X ? -1 : 1; 29 | var X0 = end.X + ((convert * ArrowLength) * Math.Cos(Move0)); 30 | var Y0 = end.Y + ((convert * ArrowLength) * Math.Sin(Move0)); 31 | var X1 = end.X + ((convert * ArrowLength) * Math.Cos(Move1)); 32 | var Y1 = end.Y + ((convert * ArrowLength) * Math.Sin(Move1)); 33 | var point3 = new Point(X0, Y0); 34 | var point5 = new Point(X1, Y1); 35 | var point2 = new Point(X0 + 0.25 * (X1 - X0), Y0 + 0.25 * (Y1 - Y0)); 36 | var point4 = new Point(X0 + 0.75 * (X1 - X0), Y0 + 0.75 * (Y1 - Y0)); 37 | return new List() 38 | { 39 | start, 40 | new Point(X0 + 0.25 * (X1 - X0), Y0 + 0.25 * (Y1 - Y0)), 41 | new Point(X0, Y0), 42 | end, 43 | new Point(X1, Y1), 44 | new Point(X0 + 0.75 * (X1 - X0), Y0 + 0.75 * (Y1 - Y0)), 45 | start 46 | }; 47 | } 48 | 49 | #region 属性 Current 50 | private static ArrowTool _Current = null; 51 | public static ArrowTool Current 52 | { 53 | get 54 | { 55 | return _Current; 56 | } 57 | } 58 | #endregion 59 | 60 | #region LineThickness DependencyProperty 61 | public double LineThickness 62 | { 63 | get { return (double)GetValue(LineThicknessProperty); } 64 | set { SetValue(LineThicknessProperty, value); } 65 | } 66 | public static readonly DependencyProperty LineThicknessProperty = 67 | DependencyProperty.Register("LineThickness", typeof(double), typeof(ArrowTool), 68 | new PropertyMetadata(5.0, new PropertyChangedCallback(ArrowTool.OnLineThicknessPropertyChanged))); 69 | 70 | private static void OnLineThicknessPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 71 | { 72 | if (obj is ArrowTool) 73 | { 74 | (obj as ArrowTool).OnLineThicknessValueChanged(); 75 | } 76 | } 77 | 78 | protected void OnLineThicknessValueChanged() 79 | { 80 | ArrowLength = LineThickness * 2 + 7; 81 | } 82 | #endregion 83 | 84 | #region LineBrush DependencyProperty 85 | public SolidColorBrush LineBrush 86 | { 87 | get { return (SolidColorBrush)GetValue(LineBrushProperty); } 88 | set { SetValue(LineBrushProperty, value); } 89 | } 90 | public static readonly DependencyProperty LineBrushProperty = 91 | DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(ArrowTool), 92 | new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(ArrowTool.OnLineBrushPropertyChanged))); 93 | 94 | private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 95 | { 96 | if (obj is ArrowTool) 97 | { 98 | (obj as ArrowTool).OnLineBrushValueChanged(); 99 | } 100 | } 101 | 102 | protected void OnLineBrushValueChanged() 103 | { 104 | 105 | } 106 | #endregion 107 | 108 | #region ArrowLength DependencyProperty 109 | public double ArrowLength 110 | { 111 | get { return (double)GetValue(ArrowLengthProperty); } 112 | set { SetValue(ArrowLengthProperty, value); } 113 | } 114 | public static readonly DependencyProperty ArrowLengthProperty = 115 | DependencyProperty.Register("ArrowLength", typeof(double), typeof(ArrowTool), 116 | new PropertyMetadata(17.0, new PropertyChangedCallback(ArrowTool.OnArrowLengthPropertyChanged))); 117 | 118 | private static void OnArrowLengthPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 119 | { 120 | if (obj is ArrowTool) 121 | { 122 | (obj as ArrowTool).OnArrowLengthValueChanged(); 123 | } 124 | } 125 | 126 | protected void OnArrowLengthValueChanged() 127 | { 128 | 129 | } 130 | #endregion 131 | 132 | #region ArrowAngle DependencyProperty 133 | public double ArrowAngle 134 | { 135 | get { return (double)GetValue(ArrowAngleProperty); } 136 | set { SetValue(ArrowAngleProperty, value); } 137 | } 138 | public static readonly DependencyProperty ArrowAngleProperty = 139 | DependencyProperty.Register("ArrowAngle", typeof(double), typeof(ArrowTool), 140 | new PropertyMetadata(0.45, new PropertyChangedCallback(ArrowTool.OnArrowAnglePropertyChanged))); 141 | 142 | private static void OnArrowAnglePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 143 | { 144 | if (obj is ArrowTool) 145 | { 146 | (obj as ArrowTool).OnArrowAngleValueChanged(); 147 | } 148 | } 149 | 150 | protected void OnArrowAngleValueChanged() 151 | { 152 | 153 | } 154 | #endregion 155 | 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /ComeCapture/Controls/EllipseTool.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class EllipseTool : StackPanel 8 | { 9 | static EllipseTool() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(EllipseTool), new FrameworkPropertyMetadata(typeof(EllipseTool))); 12 | } 13 | 14 | public EllipseTool() 15 | { 16 | _Current = this; 17 | } 18 | 19 | #region 属性 Current 20 | private static EllipseTool _Current = null; 21 | public static EllipseTool Current 22 | { 23 | get 24 | { 25 | return _Current; 26 | } 27 | } 28 | #endregion 29 | 30 | #region LineThickness DependencyProperty 31 | public double LineThickness 32 | { 33 | get { return (double)GetValue(LineThicknessProperty); } 34 | set { SetValue(LineThicknessProperty, value); } 35 | } 36 | public static readonly DependencyProperty LineThicknessProperty = 37 | DependencyProperty.Register("LineThickness", typeof(double), typeof(EllipseTool), 38 | new PropertyMetadata(5.0, new PropertyChangedCallback(EllipseTool.OnLineThicknessPropertyChanged))); 39 | 40 | private static void OnLineThicknessPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 41 | { 42 | if (obj is EllipseTool) 43 | { 44 | (obj as EllipseTool).OnLineThicknessValueChanged(); 45 | } 46 | } 47 | 48 | protected void OnLineThicknessValueChanged() 49 | { 50 | 51 | } 52 | #endregion 53 | 54 | #region LineBrush DependencyProperty 55 | public SolidColorBrush LineBrush 56 | { 57 | get { return (SolidColorBrush)GetValue(LineBrushProperty); } 58 | set { SetValue(LineBrushProperty, value); } 59 | } 60 | public static readonly DependencyProperty LineBrushProperty = 61 | DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(EllipseTool), 62 | new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(EllipseTool.OnLineBrushPropertyChanged))); 63 | 64 | private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 65 | { 66 | if (obj is EllipseTool) 67 | { 68 | (obj as EllipseTool).OnLineBrushValueChanged(); 69 | } 70 | } 71 | 72 | protected void OnLineBrushValueChanged() 73 | { 74 | 75 | } 76 | #endregion 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ComeCapture/Controls/ImageEditBar.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Models; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class ImageEditBar : Control 8 | { 9 | static ImageEditBar() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageEditBar), new FrameworkPropertyMetadata(typeof(ImageEditBar))); 12 | } 13 | 14 | public ImageEditBar() 15 | { 16 | _Current = this; 17 | } 18 | 19 | #region 属性 Current 20 | private static ImageEditBar _Current = null; 21 | public static ImageEditBar Current 22 | { 23 | get 24 | { 25 | return _Current; 26 | } 27 | set 28 | { 29 | _Current = value; 30 | } 31 | } 32 | #endregion 33 | 34 | #region 定位 35 | public void ResetCanvas() 36 | { 37 | ResetCanvasLeft(); 38 | ResetCanvasTop(); 39 | } 40 | #endregion 41 | 42 | #region CanvasLeft DependencyProperty 43 | public double CanvasLeft 44 | { 45 | get { return (double)GetValue(CanvasLeftProperty); } 46 | set { SetValue(CanvasLeftProperty, value); } 47 | } 48 | public static readonly DependencyProperty CanvasLeftProperty = 49 | DependencyProperty.Register("CanvasLeft", typeof(double), typeof(ImageEditBar), 50 | new PropertyMetadata(0.0, new PropertyChangedCallback(ImageEditBar.OnCanvasLeftPropertyChanged))); 51 | 52 | private static void OnCanvasLeftPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 53 | { 54 | if (obj is ImageEditBar) 55 | { 56 | (obj as ImageEditBar).OnCanvasLeftValueChanged(); 57 | } 58 | } 59 | 60 | protected void OnCanvasLeftValueChanged() 61 | { 62 | 63 | } 64 | 65 | private void ResetCanvasLeft() 66 | { 67 | CanvasLeft = AppModel.Current.MaskRightWidth > MainWindow.ScreenWidth - Width ? 0 : MainWindow.ScreenWidth - AppModel.Current.MaskRightWidth - Width; 68 | } 69 | #endregion 70 | 71 | #region CanvasTop DependencyProperty 72 | public double CanvasTop 73 | { 74 | get { return (double)GetValue(CanvasTopProperty); } 75 | set { SetValue(CanvasTopProperty, value); } 76 | } 77 | public static readonly DependencyProperty CanvasTopProperty = 78 | DependencyProperty.Register("CanvasTop", typeof(double), typeof(ImageEditBar), 79 | new PropertyMetadata(0.0, new PropertyChangedCallback(ImageEditBar.OnCanvasTopPropertyChanged))); 80 | 81 | private static void OnCanvasTopPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 82 | { 83 | if (obj is ImageEditBar) 84 | { 85 | (obj as ImageEditBar).OnCanvasTopValueChanged(); 86 | } 87 | } 88 | 89 | protected void OnCanvasTopValueChanged() 90 | { 91 | 92 | } 93 | 94 | private void ResetCanvasTop() 95 | { 96 | var need = 30 + (SizeColorBar.Current.Selected == Tool.Null ? 0 : 37); 97 | CanvasTop = AppModel.Current.MaskBottomHeight >= need ? MainWindow.ScreenHeight - AppModel.Current.MaskBottomHeight + 5 98 | : AppModel.Current.MaskTopHeight >= need ? AppModel.Current.MaskTopHeight - 30 99 | : AppModel.Current.MaskTopHeight; 100 | } 101 | #endregion 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ComeCapture/Controls/KeyboardTextBox.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Input; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class KeyboardTextBox : Control 8 | { 9 | static KeyboardTextBox() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(KeyboardTextBox), new FrameworkPropertyMetadata(typeof(KeyboardTextBox))); 12 | } 13 | 14 | public KeyboardTextBox() 15 | { 16 | AddHandler(PreviewKeyDownEvent, new KeyEventHandler(Keyboard_KeyDown)); 17 | DataContext = AppModel.Current; 18 | } 19 | 20 | #region 键盘事件:只允许输入数字以及字母 21 | private void Keyboard_KeyDown(object sender, KeyEventArgs e) 22 | { 23 | var key = (int)e.Key; 24 | var textbox = e.OriginalSource as TextBox; 25 | //A-Z 26 | if (key >= 44 && key <= 69) 27 | { 28 | textbox.Text = e.Key.ToString(); 29 | textbox.Select(1, 0); 30 | } 31 | else if (key >= 34 && key <= 43) //0 - 9, 32 | { 33 | textbox.Text = e.Key.ToString().Substring(1); 34 | textbox.Select(1, 0); 35 | } 36 | e.Handled = true; 37 | } 38 | #endregion 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ComeCapture/Controls/LineTool.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class LineTool : StackPanel 8 | { 9 | static LineTool() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(LineTool), new FrameworkPropertyMetadata(typeof(LineTool))); 12 | } 13 | 14 | public LineTool() 15 | { 16 | _Current = this; 17 | } 18 | 19 | #region 属性 Current 20 | private static LineTool _Current = null; 21 | public static LineTool Current 22 | { 23 | get 24 | { 25 | return _Current; 26 | } 27 | } 28 | #endregion 29 | 30 | #region LineThickness DependencyProperty 31 | public double LineThickness 32 | { 33 | get { return (double)GetValue(LineThicknessProperty); } 34 | set { SetValue(LineThicknessProperty, value); } 35 | } 36 | public static readonly DependencyProperty LineThicknessProperty = 37 | DependencyProperty.Register("LineThickness", typeof(double), typeof(LineTool), 38 | new PropertyMetadata(5.0, new PropertyChangedCallback(LineTool.OnLineThicknessPropertyChanged))); 39 | 40 | private static void OnLineThicknessPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 41 | { 42 | if (obj is LineTool) 43 | { 44 | (obj as LineTool).OnLineThicknessValueChanged(); 45 | } 46 | } 47 | 48 | protected void OnLineThicknessValueChanged() 49 | { 50 | 51 | } 52 | #endregion 53 | 54 | #region LineBrush DependencyProperty 55 | public SolidColorBrush LineBrush 56 | { 57 | get { return (SolidColorBrush)GetValue(LineBrushProperty); } 58 | set { SetValue(LineBrushProperty, value); } 59 | } 60 | public static readonly DependencyProperty LineBrushProperty = 61 | DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(LineTool), 62 | new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(LineTool.OnLineBrushPropertyChanged))); 63 | 64 | private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 65 | { 66 | if (obj is LineTool) 67 | { 68 | (obj as LineTool).OnLineBrushValueChanged(); 69 | } 70 | } 71 | 72 | protected void OnLineBrushValueChanged() 73 | { 74 | 75 | } 76 | #endregion 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ComeCapture/Controls/MainImage.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Helpers; 2 | using ComeCapture.Models; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Controls.Primitives; 8 | using System.Windows.Input; 9 | using System.Windows.Media; 10 | using System.Windows.Shapes; 11 | 12 | namespace ComeCapture.Controls 13 | { 14 | public class MainImage : Control 15 | { 16 | public Point point; 17 | 18 | private Rectangle _Rectangle = null; 19 | private Ellipse _Ellipse = null; 20 | private List points = null; 21 | private Path _Line = null; 22 | private StreamGeometry geometry = new StreamGeometry(); 23 | public TextBoxControl _Text = null; 24 | private Path _Arrow = null; 25 | 26 | static MainImage() 27 | { 28 | DefaultStyleKeyProperty.OverrideMetadata(typeof(MainImage), new FrameworkPropertyMetadata(typeof(MainImage))); 29 | } 30 | 31 | public MainImage() 32 | { 33 | _Current = this; 34 | AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(OnDragStart)); 35 | AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(OnDragCompleted)); 36 | AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(OnDragDelta)); 37 | AddHandler(MouseMoveEvent, new MouseEventHandler(OnMove)); 38 | Limit = new Limit(); 39 | } 40 | 41 | #region 属性 Current 42 | private static MainImage _Current = null; 43 | public static MainImage Current 44 | { 45 | get 46 | { 47 | return _Current; 48 | } 49 | set 50 | { 51 | _Current = value; 52 | } 53 | } 54 | #endregion 55 | 56 | #region MoveCursor DependencyProperty 57 | public Cursor MoveCursor 58 | { 59 | get { return (Cursor)GetValue(MoveCursorProperty); } 60 | set { SetValue(MoveCursorProperty, value); } 61 | } 62 | public static readonly DependencyProperty MoveCursorProperty = 63 | DependencyProperty.Register("MoveCursor", typeof(Cursor), typeof(MainImage), 64 | new PropertyMetadata(Cursors.SizeAll, new PropertyChangedCallback(MainImage.OnMoveCursorPropertyChanged))); 65 | 66 | private static void OnMoveCursorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 67 | { 68 | if (obj is MainImage) 69 | { 70 | (obj as MainImage).OnMoveCursorValueChanged(); 71 | } 72 | } 73 | 74 | protected void OnMoveCursorValueChanged() 75 | { 76 | 77 | } 78 | #endregion 79 | 80 | #region Direction DependencyProperty 81 | public Direction Direction 82 | { 83 | get { return (Direction)GetValue(DirectionProperty); } 84 | set { SetValue(DirectionProperty, value); } 85 | } 86 | public static readonly DependencyProperty DirectionProperty = 87 | DependencyProperty.Register("Direction", typeof(Direction), typeof(MainImage), 88 | new PropertyMetadata(Direction.Null, new PropertyChangedCallback(MainImage.OnDirectionPropertyChanged))); 89 | 90 | private static void OnDirectionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 91 | { 92 | if (obj is MainImage) 93 | { 94 | (obj as MainImage).OnDirectionValueChanged(); 95 | } 96 | } 97 | 98 | protected void OnDirectionValueChanged() 99 | { 100 | 101 | } 102 | #endregion 103 | 104 | #region Limit DependencyProperty 105 | public Limit Limit 106 | { 107 | get { return (Limit)GetValue(LimitProperty); } 108 | set { SetValue(LimitProperty, value); } 109 | } 110 | public static readonly DependencyProperty LimitProperty = 111 | DependencyProperty.Register("Limit", typeof(Limit), typeof(MainImage), 112 | new PropertyMetadata(null, new PropertyChangedCallback(MainImage.OnLimitPropertyChanged))); 113 | 114 | private static void OnLimitPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 115 | { 116 | if (obj is MainImage) 117 | { 118 | (obj as MainImage).OnLimitValueChanged(); 119 | } 120 | } 121 | 122 | protected void OnLimitValueChanged() 123 | { 124 | 125 | } 126 | #endregion 127 | 128 | #region ZoomThumbVisibility DependencyProperty 129 | public Visibility ZoomThumbVisibility 130 | { 131 | get { return (Visibility)GetValue(ZoomThumbVisibilityProperty); } 132 | set { SetValue(ZoomThumbVisibilityProperty, value); } 133 | } 134 | public static readonly DependencyProperty ZoomThumbVisibilityProperty = 135 | DependencyProperty.Register("ZoomThumbVisibility", typeof(Visibility), typeof(MainImage), 136 | new PropertyMetadata(Visibility.Visible, new PropertyChangedCallback(MainImage.OnZoomThumbVisibilityPropertyChanged))); 137 | 138 | private static void OnZoomThumbVisibilityPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 139 | { 140 | if (obj is MainImage) 141 | { 142 | (obj as MainImage).OnZoomThumbVisibilityValueChanged(); 143 | } 144 | } 145 | 146 | protected void OnZoomThumbVisibilityValueChanged() 147 | { 148 | 149 | } 150 | #endregion 151 | 152 | #region 开始滑动事件 153 | private void OnDragStart(object sender, DragStartedEventArgs e) 154 | { 155 | Direction = (e.OriginalSource as ZoomThumb).Direction; 156 | if (SizeColorBar.Current.Selected != Tool.Null) 157 | { 158 | point = Mouse.GetPosition(this); 159 | if (SizeColorBar.Current.Selected == Tool.Text) 160 | { 161 | DrawText(); 162 | } 163 | } 164 | } 165 | #endregion 166 | 167 | #region 滑动中事件 168 | private void OnDragDelta(object sender, DragDeltaEventArgs e) 169 | { 170 | var X = e.HorizontalChange; 171 | var Y = e.VerticalChange; 172 | switch (Direction) 173 | { 174 | case Direction.Move: 175 | if (SizeColorBar.Current.Selected == Tool.Null) 176 | { 177 | OnMove(X, Y); 178 | } 179 | else 180 | { 181 | switch (SizeColorBar.Current.Selected) 182 | { 183 | case Tool.Rectangle: 184 | DrawRectangle(X, Y); 185 | break; 186 | case Tool.Ellipse: 187 | DrawEllipse(X, Y); 188 | break; 189 | case Tool.Arrow: 190 | DrawArrow(X, Y); 191 | break; 192 | case Tool.Line: 193 | DrawLine(X, Y); 194 | break; 195 | case Tool.Text: 196 | break; 197 | default: 198 | break; 199 | } 200 | } 201 | break; 202 | case Direction.Null: 203 | break; 204 | default: 205 | var str = Direction.ToString(); 206 | if (X != 0) 207 | { 208 | if (str.Contains("Left")) 209 | { 210 | Left(X); 211 | } 212 | if (str.Contains("Right")) 213 | { 214 | Right(X); 215 | } 216 | } 217 | if (Y != 0) 218 | { 219 | if (str.Contains("Top")) 220 | { 221 | Top(Y); 222 | } 223 | if (str.Contains("Bottom")) 224 | { 225 | Bottom(Y); 226 | } 227 | } 228 | AppModel.Current.ChangeShowSize(); 229 | break; 230 | } 231 | ImageEditBar.Current.ResetCanvas(); 232 | SizeColorBar.Current.ResetCanvas(); 233 | } 234 | #endregion 235 | 236 | #region 滑动结束事件 237 | private void OnDragCompleted(object sender, DragCompletedEventArgs e) 238 | { 239 | if (Direction == Direction.Move && SizeColorBar.Current.Selected != Tool.Null) 240 | { 241 | switch (SizeColorBar.Current.Selected) 242 | { 243 | case Tool.Rectangle: 244 | if (_Rectangle != null) 245 | { 246 | ResetLimit(Canvas.GetLeft(_Rectangle), Canvas.GetTop(_Rectangle), Canvas.GetLeft(_Rectangle) + _Rectangle.Width, Canvas.GetTop(_Rectangle) + _Rectangle.Height); 247 | MainWindow.Register(_Rectangle); 248 | _Rectangle = null; 249 | } 250 | break; 251 | case Tool.Ellipse: 252 | if (_Ellipse != null) 253 | { 254 | ResetLimit(Canvas.GetLeft(_Ellipse), Canvas.GetTop(_Ellipse), Canvas.GetLeft(_Ellipse) + _Ellipse.Width, Canvas.GetTop(_Ellipse) + _Ellipse.Height); 255 | MainWindow.Register(_Ellipse); 256 | _Ellipse = null; 257 | } 258 | break; 259 | case Tool.Arrow: 260 | if (_Arrow != null) 261 | { 262 | geometry.Clear(); 263 | ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y)); 264 | points = null; 265 | MainWindow.Register(_Arrow); 266 | _Arrow = null; 267 | } 268 | break; 269 | case Tool.Line: 270 | if (_Line != null) 271 | { 272 | geometry.Clear(); 273 | ResetLimit(points.Min(p => p.X), points.Min(p => p.Y), points.Max(p => p.X), points.Max(p => p.Y)); 274 | points = null; 275 | MainWindow.Register(_Line); 276 | _Line = null; 277 | } 278 | break; 279 | case Tool.Text: 280 | break; 281 | default: 282 | break; 283 | } 284 | } 285 | Direction = Direction.Null; 286 | } 287 | #endregion 288 | 289 | #region 画矩形 290 | private void DrawRectangle(double X, double Y) 291 | { 292 | if (_Rectangle == null) 293 | { 294 | _Rectangle = new Rectangle() 295 | { 296 | Fill = new SolidColorBrush(Colors.Transparent), 297 | Stroke = RectangleTool.Current.LineBrush, 298 | StrokeThickness = RectangleTool.Current.LineThickness 299 | }; 300 | Panel.SetZIndex(_Rectangle, -1); 301 | MainWindow.AddControl(_Rectangle); 302 | } 303 | if (X > 0) 304 | { 305 | Canvas.SetLeft(_Rectangle, point.X + AppModel.Current.MaskLeftWidth); 306 | _Rectangle.Width = X < Width - point.X ? X : Width - point.X; 307 | } 308 | else 309 | { 310 | Canvas.SetLeft(_Rectangle, -X < point.X ? point.X + X + AppModel.Current.MaskLeftWidth : AppModel.Current.MaskLeftWidth); 311 | _Rectangle.Width = -X < point.X ? -X : point.X; 312 | } 313 | if (Y > 0) 314 | { 315 | Canvas.SetTop(_Rectangle, point.Y + AppModel.Current.MaskTopHeight); 316 | _Rectangle.Height = Y < Height - point.Y ? Y : Height - point.Y; 317 | } 318 | else 319 | { 320 | Canvas.SetTop(_Rectangle, -Y < point.Y ? point.Y + Y + AppModel.Current.MaskTopHeight : AppModel.Current.MaskTopHeight); 321 | _Rectangle.Height = -Y < point.Y ? -Y : point.Y; 322 | } 323 | } 324 | #endregion 325 | 326 | #region 画椭圆 327 | private void DrawEllipse(double X, double Y) 328 | { 329 | if (_Ellipse == null) 330 | { 331 | _Ellipse = new Ellipse() 332 | { 333 | Fill = new SolidColorBrush(Colors.Transparent), 334 | Stroke = EllipseTool.Current.LineBrush, 335 | StrokeThickness = EllipseTool.Current.LineThickness 336 | }; 337 | Panel.SetZIndex(_Ellipse, -1); 338 | MainWindow.AddControl(_Ellipse); 339 | } 340 | if (X > 0) 341 | { 342 | Canvas.SetLeft(_Ellipse, point.X + AppModel.Current.MaskLeftWidth); 343 | _Ellipse.Width = X < Width - point.X ? X : Width - point.X; 344 | } 345 | else 346 | { 347 | Canvas.SetLeft(_Ellipse, -X < point.X ? point.X + X + AppModel.Current.MaskLeftWidth : AppModel.Current.MaskLeftWidth); 348 | _Ellipse.Width = -X < point.X ? -X : point.X; 349 | } 350 | if (Y > 0) 351 | { 352 | Canvas.SetTop(_Ellipse, point.Y + AppModel.Current.MaskTopHeight); 353 | _Ellipse.Height = Y < Height - point.Y ? Y : Height - point.Y; 354 | } 355 | else 356 | { 357 | Canvas.SetTop(_Ellipse, -Y < point.Y ? point.Y + Y + AppModel.Current.MaskTopHeight : AppModel.Current.MaskTopHeight); 358 | _Ellipse.Height = -Y < point.Y ? -Y : point.Y; 359 | } 360 | } 361 | #endregion 362 | 363 | #region 画箭头 364 | private void DrawArrow(double X, double Y) 365 | { 366 | var screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight); 367 | if (_Arrow == null) 368 | { 369 | _Arrow = new Path() 370 | { 371 | Fill = ArrowTool.Current.LineBrush, 372 | StrokeThickness = ArrowTool.Current.LineThickness 373 | }; 374 | Panel.SetZIndex(_Arrow, -1); 375 | MainWindow.AddControl(_Arrow); 376 | } 377 | var point2 = new Point(screen.X + X, screen.Y + Y); 378 | point2.X = point2.X < AppModel.Current.MaskLeftWidth ? AppModel.Current.MaskLeftWidth : point2.X > AppModel.Current.MaskLeftWidth + Width ? AppModel.Current.MaskLeftWidth + Width : point2.X; 379 | point2.Y = point2.Y < AppModel.Current.MaskTopHeight ? AppModel.Current.MaskTopHeight : point2.Y > AppModel.Current.MaskTopHeight + Height ? AppModel.Current.MaskTopHeight + Height : point2.Y; 380 | points = ArrowTool.Current.CreateArrow(screen, point2); 381 | 382 | using (var ctx = geometry.Open()) 383 | { 384 | for (int i = 0; i < points.Count; i++) 385 | { 386 | if (i == 0) 387 | { 388 | ctx.BeginFigure(points[0], true, false); 389 | } 390 | else 391 | { 392 | ctx.LineTo(points[i], true, true); 393 | } 394 | } 395 | } 396 | _Arrow.Data = geometry.Clone(); 397 | } 398 | #endregion 399 | 400 | #region 画刷 401 | private void DrawLine(double X, double Y) 402 | { 403 | var screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight); 404 | if (_Line == null) 405 | { 406 | _Line = new Path() 407 | { 408 | Stroke = LineTool.Current.LineBrush, 409 | StrokeThickness = LineTool.Current.LineThickness 410 | }; 411 | points = new List 412 | { 413 | screen 414 | }; 415 | Panel.SetZIndex(_Line, -1); 416 | MainWindow.AddControl(_Line); 417 | } 418 | var point2 = new Point(screen.X + X, screen.Y + Y); 419 | point2.X = point2.X < AppModel.Current.MaskLeftWidth ? AppModel.Current.MaskLeftWidth : point2.X > AppModel.Current.MaskLeftWidth + Width ? AppModel.Current.MaskLeftWidth + Width : point2.X; 420 | point2.Y = point2.Y < AppModel.Current.MaskTopHeight ? AppModel.Current.MaskTopHeight : point2.Y > AppModel.Current.MaskTopHeight + Height ? AppModel.Current.MaskTopHeight + Height : point2.Y; 421 | points.Add(point2); 422 | using (var ctx = geometry.Open()) 423 | { 424 | for (int i = 0; i < points.Count; i++) 425 | { 426 | if (i == 0) 427 | { 428 | ctx.BeginFigure(points[0], true, false); 429 | } 430 | else 431 | { 432 | ctx.LineTo(points[i], true, true); 433 | } 434 | } 435 | } 436 | _Line.Data = geometry.Clone(); 437 | } 438 | #endregion 439 | 440 | #region 添加输入框 441 | private void DrawText() 442 | { 443 | if (_Text != null) 444 | { 445 | Focus(); 446 | } 447 | else 448 | { 449 | _Text = new TextBoxControl() 450 | { 451 | FontSize = TextTool.Current.FontSize, 452 | Foreground = TextTool.Current.LineBrush 453 | }; 454 | if (point.X > Width - 36) 455 | { 456 | point.X = Width - 36; 457 | } 458 | if (point.Y > Height - 22) 459 | { 460 | point.Y = Height - 22; 461 | } 462 | var screen = new Point(point.X + AppModel.Current.MaskLeftWidth, point.Y + AppModel.Current.MaskTopHeight); 463 | Canvas.SetLeft(_Text, screen.X); 464 | Canvas.SetTop(_Text, screen.Y); 465 | MainWindow.AddControl(_Text); 466 | } 467 | } 468 | #endregion 469 | 470 | #region 拖动截图区域 471 | private void OnMove(double X, double Y) 472 | { 473 | #region X轴移动 474 | if (X > 0) 475 | { 476 | var max = AppModel.Current.MaskRightWidth > Limit.Left - AppModel.Current.MaskLeftWidth ? Limit.Left - AppModel.Current.MaskLeftWidth : AppModel.Current.MaskRightWidth; 477 | if (X > max) 478 | { 479 | X = max; 480 | } 481 | } 482 | else 483 | { 484 | var max = AppModel.Current.MaskLeftWidth > AppModel.Current.MaskLeftWidth + Width - Limit.Right ? AppModel.Current.MaskLeftWidth + Width - Limit.Right : AppModel.Current.MaskLeftWidth; 485 | if (-X > max) 486 | { 487 | X = -max; 488 | } 489 | } 490 | if (X != 0) 491 | { 492 | AppModel.Current.MaskLeftWidth += X; 493 | AppModel.Current.MaskRightWidth -= X; 494 | Canvas.SetLeft(this, Canvas.GetLeft(this) + X); 495 | } 496 | #endregion 497 | 498 | #region Y轴移动 499 | if (Y > 0) 500 | { 501 | var max = AppModel.Current.MaskBottomHeight > Limit.Top - AppModel.Current.MaskTopHeight ? Limit.Top - AppModel.Current.MaskTopHeight : AppModel.Current.MaskBottomHeight; 502 | if (Y > max) 503 | { 504 | Y = max; 505 | } 506 | } 507 | else 508 | { 509 | var max = AppModel.Current.MaskTopHeight > AppModel.Current.MaskTopHeight + Height - Limit.Bottom ? AppModel.Current.MaskTopHeight + Height - Limit.Bottom : AppModel.Current.MaskTopHeight; 510 | if (-Y > max) 511 | { 512 | Y = -max; 513 | } 514 | } 515 | if (Y != 0) 516 | { 517 | AppModel.Current.MaskTopHeight += Y; 518 | AppModel.Current.MaskBottomHeight -= Y; 519 | Canvas.SetTop(this, Canvas.GetTop(this) + Y); 520 | } 521 | #endregion 522 | } 523 | #endregion 524 | 525 | #region 左缩放 526 | private void Left(double X) 527 | { 528 | if (X > 0) 529 | { 530 | var max = MainWindow.Current.list.Count == 0 ? Width - MainWindow.MinSize 531 | : Limit.Left - AppModel.Current.MaskLeftWidth < Width - MainWindow.MinSize ? Limit.Left - AppModel.Current.MaskLeftWidth 532 | : Width - MainWindow.MinSize; 533 | if (X > max) 534 | { 535 | X = max; 536 | } 537 | } 538 | else 539 | { 540 | var max = AppModel.Current.MaskLeftWidth; 541 | if (-X > max) 542 | { 543 | X = -max; 544 | } 545 | } 546 | if (X != 0) 547 | { 548 | Width -= X; 549 | Canvas.SetLeft(this, Canvas.GetLeft(this) + X); 550 | AppModel.Current.MaskLeftWidth += X; 551 | AppModel.Current.MaskTopWidth -= X; 552 | } 553 | } 554 | #endregion 555 | 556 | #region 右缩放 557 | private void Right(double X) 558 | { 559 | if (X > 0) 560 | { 561 | var max = AppModel.Current.MaskRightWidth; 562 | if (X > max) 563 | { 564 | X = max; 565 | } 566 | } 567 | else 568 | { 569 | var max = MainWindow.Current.list.Count == 0 ? Width - MainWindow.MinSize 570 | : AppModel.Current.MaskLeftWidth + Width - Limit.Right < Width - MainWindow.MinSize ? AppModel.Current.MaskLeftWidth + Width - Limit.Right 571 | : Width - MainWindow.MinSize; 572 | if (-X > max) 573 | { 574 | X = -max; 575 | } 576 | } 577 | if (X != 0) 578 | { 579 | Width += X; 580 | AppModel.Current.MaskRightWidth -= X; 581 | AppModel.Current.MaskTopWidth += X; 582 | } 583 | } 584 | #endregion 585 | 586 | #region 上缩放 587 | private void Top(double Y) 588 | { 589 | if (Y > 0) 590 | { 591 | var max = MainWindow.Current.list.Count == 0 ? Height - MainWindow.MinSize 592 | : Limit.Top - AppModel.Current.MaskTopHeight < Height - MainWindow.MinSize ? Limit.Top - AppModel.Current.MaskTopHeight 593 | : Height - MainWindow.MinSize; 594 | if (Y > max) 595 | { 596 | Y = max; 597 | } 598 | } 599 | else 600 | { 601 | var max = AppModel.Current.MaskLeftWidth; 602 | if (-Y > max) 603 | { 604 | Y = -max; 605 | } 606 | } 607 | if (Y != 0) 608 | { 609 | Height -= Y; 610 | Canvas.SetTop(this, Canvas.GetTop(this) + Y); 611 | AppModel.Current.MaskTopHeight += Y; 612 | } 613 | } 614 | #endregion 615 | 616 | #region 下缩放 617 | private void Bottom(double Y) 618 | { 619 | if (Y > 0) 620 | { 621 | var max = AppModel.Current.MaskBottomHeight; 622 | if (Y > max) 623 | { 624 | Y = max; 625 | } 626 | } 627 | else 628 | { 629 | var max = MainWindow.Current.list.Count == 0 ? Height - MainWindow.MinSize 630 | : AppModel.Current.MaskTopHeight + Height - Limit.Bottom < Height - MainWindow.MinSize ? AppModel.Current.MaskTopHeight + Height - Limit.Bottom 631 | : Height - MainWindow.MinSize; 632 | if (-Y > max) 633 | { 634 | Y = -max; 635 | } 636 | } 637 | if (Y != 0) 638 | { 639 | Height += Y; 640 | AppModel.Current.MaskBottomHeight -= Y; 641 | } 642 | } 643 | #endregion 644 | 645 | #region 刷新RGB 646 | private void OnMove(object sender, MouseEventArgs e) 647 | { 648 | var point = PointToScreen(e.GetPosition(this)); 649 | AppModel.Current.ShowRGB = ImageHelper.GetRGB((int)point.X, (int)point.Y); 650 | } 651 | #endregion 652 | 653 | #region 计算图片移动的极限值 654 | public void ResetLimit(double left, double top, double right, double bottom) 655 | { 656 | ResetLeft(left); 657 | ResetTop(top); 658 | ResetRight(right); 659 | ResetButtom(bottom); 660 | } 661 | 662 | private void ResetLeft(double value) 663 | { 664 | if (value < Limit.Left) 665 | { 666 | Limit.Left = value; 667 | } 668 | } 669 | 670 | private void ResetTop(double value) 671 | { 672 | if (value < Limit.Top) 673 | { 674 | Limit.Top = value; 675 | } 676 | } 677 | 678 | private void ResetRight(double value) 679 | { 680 | if (value > Limit.Right) 681 | { 682 | Limit.Right = value; 683 | } 684 | } 685 | 686 | private void ResetButtom(double value) 687 | { 688 | if (value > Limit.Bottom) 689 | { 690 | Limit.Bottom = value; 691 | } 692 | } 693 | #endregion 694 | } 695 | } 696 | -------------------------------------------------------------------------------- /ComeCapture/Controls/RectangleTool.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class RectangleTool : StackPanel 8 | { 9 | static RectangleTool() 10 | { 11 | DefaultStyleKeyProperty.OverrideMetadata(typeof(RectangleTool), new FrameworkPropertyMetadata(typeof(RectangleTool))); 12 | } 13 | 14 | public RectangleTool() 15 | { 16 | _Current = this; 17 | } 18 | 19 | #region 属性 Current 20 | private static RectangleTool _Current = null; 21 | public static RectangleTool Current 22 | { 23 | get 24 | { 25 | return _Current; 26 | } 27 | } 28 | #endregion 29 | 30 | #region LineThickness DependencyProperty 31 | public double LineThickness 32 | { 33 | get { return (double)GetValue(LineThicknessProperty); } 34 | set { SetValue(LineThicknessProperty, value); } 35 | } 36 | public static readonly DependencyProperty LineThicknessProperty = 37 | DependencyProperty.Register("LineThickness", typeof(double), typeof(RectangleTool), 38 | new PropertyMetadata(5.0, new PropertyChangedCallback(RectangleTool.OnLineThicknessPropertyChanged))); 39 | 40 | private static void OnLineThicknessPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 41 | { 42 | if (obj is RectangleTool) 43 | { 44 | (obj as RectangleTool).OnLineThicknessValueChanged(); 45 | } 46 | } 47 | 48 | protected void OnLineThicknessValueChanged() 49 | { 50 | 51 | } 52 | #endregion 53 | 54 | #region LineBrush DependencyProperty 55 | public SolidColorBrush LineBrush 56 | { 57 | get { return (SolidColorBrush)GetValue(LineBrushProperty); } 58 | set { SetValue(LineBrushProperty, value); } 59 | } 60 | public static readonly DependencyProperty LineBrushProperty = 61 | DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(RectangleTool), 62 | new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(RectangleTool.OnLineBrushPropertyChanged))); 63 | 64 | private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 65 | { 66 | if (obj is RectangleTool) 67 | { 68 | (obj as RectangleTool).OnLineBrushValueChanged(); 69 | } 70 | } 71 | 72 | protected void OnLineBrushValueChanged() 73 | { 74 | 75 | } 76 | #endregion 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ComeCapture/Controls/SizeColorBar.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Models; 2 | using System.Collections.Generic; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using System.Windows.Input; 6 | using System.Windows.Media; 7 | 8 | namespace ComeCapture.Controls 9 | { 10 | [TemplatePart(Name = "PART_RectangleTool", Type = typeof(RectangleTool))] 11 | [TemplatePart(Name = "PART_EllipseTool", Type = typeof(EllipseTool))] 12 | [TemplatePart(Name = "PART_ArrowTool", Type = typeof(ArrowTool))] 13 | [TemplatePart(Name = "PART_LineTool", Type = typeof(LineTool))] 14 | [TemplatePart(Name = "PART_TextTool", Type = typeof(TextTool))] 15 | public class SizeColorBar : Control 16 | { 17 | private RectangleTool _RectangleTool; 18 | private EllipseTool _EllipseTool; 19 | private LineTool _LineTool; 20 | private TextTool _TextTool; 21 | private ArrowTool _ArrowTool; 22 | 23 | static SizeColorBar() 24 | { 25 | DefaultStyleKeyProperty.OverrideMetadata(typeof(SizeColorBar), new FrameworkPropertyMetadata(typeof(SizeColorBar))); 26 | } 27 | 28 | public SizeColorBar() 29 | { 30 | _Current = this; 31 | } 32 | 33 | public override void OnApplyTemplate() 34 | { 35 | base.OnApplyTemplate(); 36 | _RectangleTool = GetTemplateChild("PART_RectangleTool") as RectangleTool; 37 | _EllipseTool = GetTemplateChild("PART_EllipseTool") as EllipseTool; 38 | _ArrowTool = GetTemplateChild("PART_ArrowTool") as ArrowTool; 39 | _LineTool = GetTemplateChild("PART_LineTool") as LineTool; 40 | _TextTool = GetTemplateChild("PART_TextTool") as TextTool; 41 | } 42 | 43 | public void ChangeColor(SolidColorBrush brush) 44 | { 45 | switch (Selected) 46 | { 47 | case Tool.Rectangle: 48 | _RectangleTool.LineBrush = brush; 49 | break; 50 | case Tool.Ellipse: 51 | _EllipseTool.LineBrush = brush; 52 | break; 53 | case Tool.Arrow: 54 | _ArrowTool.LineBrush = brush; 55 | break; 56 | case Tool.Line: 57 | _LineTool.LineBrush = brush; 58 | break; 59 | case Tool.Text: 60 | _TextTool.LineBrush = brush; 61 | break; 62 | default: 63 | break; 64 | } 65 | } 66 | 67 | #region 属性 Current 68 | private static SizeColorBar _Current = null; 69 | public static SizeColorBar Current 70 | { 71 | get 72 | { 73 | return _Current; 74 | } 75 | set 76 | { 77 | _Current = value; 78 | } 79 | } 80 | #endregion 81 | 82 | #region 属性 ColorBars 83 | private static List _ColorBars; 84 | public static List ColorBars 85 | { 86 | get 87 | { 88 | if (_ColorBars == null) 89 | { 90 | _ColorBars = new List() 91 | { 92 | new SolidColorBrush(Colors.Black), 93 | new SolidColorBrush(Colors.Gray), 94 | new SolidColorBrush(Colors.Firebrick), 95 | new SolidColorBrush(Colors.Orange), 96 | new SolidColorBrush(Colors.ForestGreen), 97 | new SolidColorBrush(Colors.Blue), 98 | new SolidColorBrush(Colors.Maroon), 99 | new SolidColorBrush(Colors.CadetBlue), 100 | new SolidColorBrush(Colors.HotPink), 101 | 102 | new SolidColorBrush(Colors.White), 103 | new SolidColorBrush(Colors.LightGray), 104 | new SolidColorBrush(Colors.Red), 105 | new SolidColorBrush(Colors.Yellow), 106 | new SolidColorBrush(Colors.YellowGreen), 107 | new SolidColorBrush(Colors.DodgerBlue), 108 | new SolidColorBrush(Colors.Magenta), 109 | new SolidColorBrush(Colors.Cyan), 110 | new SolidColorBrush(Colors.MistyRose) 111 | }; 112 | } 113 | return _ColorBars; 114 | } 115 | set 116 | { 117 | _ColorBars = value; 118 | } 119 | } 120 | #endregion 121 | 122 | #region 定位 123 | public void ResetCanvas() 124 | { 125 | ResetCanvasLeft(); 126 | ResetCanvasTop(); 127 | } 128 | #endregion 129 | 130 | #region CanvasLeft DependencyProperty 131 | public double CanvasLeft 132 | { 133 | get { return (double)GetValue(CanvasLeftProperty); } 134 | set { SetValue(CanvasLeftProperty, value); } 135 | } 136 | public static readonly DependencyProperty CanvasLeftProperty = 137 | DependencyProperty.Register("CanvasLeft", typeof(double), typeof(SizeColorBar), 138 | new PropertyMetadata(0.0, new PropertyChangedCallback(SizeColorBar.OnCanvasLeftPropertyChanged))); 139 | 140 | private static void OnCanvasLeftPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 141 | { 142 | if (obj is SizeColorBar) 143 | { 144 | (obj as SizeColorBar).OnCanvasLeftValueChanged(); 145 | } 146 | } 147 | 148 | protected void OnCanvasLeftValueChanged() 149 | { 150 | 151 | } 152 | 153 | private void ResetCanvasLeft() 154 | { 155 | CanvasLeft = ImageEditBar.Current.CanvasLeft; 156 | } 157 | #endregion 158 | 159 | #region CanvasTop DependencyProperty 160 | public double CanvasTop 161 | { 162 | get { return (double)GetValue(CanvasTopProperty); } 163 | set { SetValue(CanvasTopProperty, value); } 164 | } 165 | public static readonly DependencyProperty CanvasTopProperty = 166 | DependencyProperty.Register("CanvasTop", typeof(double), typeof(SizeColorBar), 167 | new PropertyMetadata(0.0, new PropertyChangedCallback(SizeColorBar.OnCanvasTopPropertyChanged))); 168 | 169 | private static void OnCanvasTopPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 170 | { 171 | if (obj is SizeColorBar) 172 | { 173 | (obj as SizeColorBar).OnCanvasTopValueChanged(); 174 | } 175 | } 176 | 177 | protected void OnCanvasTopValueChanged() 178 | { 179 | 180 | } 181 | 182 | private void ResetCanvasTop() 183 | { 184 | CanvasTop = AppModel.Current.MaskBottomHeight >= 67 ? MainWindow.ScreenHeight - AppModel.Current.MaskBottomHeight + 32 185 | : AppModel.Current.MaskTopHeight >= 67 ? AppModel.Current.MaskTopHeight - 67 186 | : AppModel.Current.MaskTopHeight + 30; 187 | } 188 | #endregion 189 | 190 | #region Selected DependencyProperty 191 | public Tool Selected 192 | { 193 | get { return (Tool)GetValue(SelectedProperty); } 194 | set { SetValue(SelectedProperty, value); } 195 | } 196 | public static readonly DependencyProperty SelectedProperty = 197 | DependencyProperty.Register("Selected", typeof(Tool), typeof(SizeColorBar), 198 | new PropertyMetadata(Tool.Null, new PropertyChangedCallback(SizeColorBar.OnSelectedPropertyChanged))); 199 | 200 | private static void OnSelectedPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 201 | { 202 | if (obj is SizeColorBar) 203 | { 204 | (obj as SizeColorBar).OnSelectedValueChanged(); 205 | } 206 | } 207 | 208 | protected void OnSelectedValueChanged() 209 | { 210 | ImageEditBar.Current.ResetCanvas(); 211 | ResetCanvas(); 212 | if (Selected == Tool.Null) 213 | { 214 | MainWindow.Current.MainImage.MoveCursor = Cursors.SizeAll; 215 | } 216 | else 217 | { 218 | MainWindow.Current.MainImage.MoveCursor = Cursors.Pen; 219 | } 220 | } 221 | #endregion 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /ComeCapture/Controls/TextBoxControl.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Media; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | [TemplatePart(Name = "PART_TextBox", Type = typeof(TextBox))] 8 | public class TextBoxControl : Control 9 | { 10 | public TextBox _TextBox; 11 | 12 | static TextBoxControl() 13 | { 14 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBoxControl), new FrameworkPropertyMetadata(typeof(TextBoxControl))); 15 | } 16 | 17 | public TextBoxControl() 18 | { 19 | AddHandler(GotFocusEvent, new RoutedEventHandler((sender, e) => 20 | { 21 | MyFocus = true; 22 | })); 23 | AddHandler(LostFocusEvent, new RoutedEventHandler((sender, e) => 24 | { 25 | MyFocus = false; 26 | })); 27 | } 28 | 29 | public override void OnApplyTemplate() 30 | { 31 | base.OnApplyTemplate(); 32 | _TextBox = GetTemplateChild("PART_TextBox") as TextBox; 33 | _TextBox.MaxWidth = MainWindow.Current.MainImage.Width - MainWindow.Current.MainImage.point.X - 3; 34 | _TextBox.MaxHeight = MainWindow.Current.MainImage.Height - MainWindow.Current.MainImage.point.Y - 3; 35 | } 36 | 37 | #region BorderColor DependencyProperty 38 | public Color BorderColor 39 | { 40 | get { return (Color)GetValue(BorderColorProperty); } 41 | set { SetValue(BorderColorProperty, value); } 42 | } 43 | public static readonly DependencyProperty BorderColorProperty = 44 | DependencyProperty.Register("BorderColor", typeof(Color), typeof(TextBoxControl), 45 | new PropertyMetadata(Colors.Transparent, new PropertyChangedCallback(TextBoxControl.OnBorderColorPropertyChanged))); 46 | 47 | private static void OnBorderColorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 48 | { 49 | if (obj is TextBoxControl) 50 | { 51 | (obj as TextBoxControl).OnBorderColorValueChanged(); 52 | } 53 | } 54 | 55 | protected void OnBorderColorValueChanged() 56 | { 57 | 58 | } 59 | #endregion 60 | 61 | #region MyFocus DependencyProperty 62 | public bool MyFocus 63 | { 64 | get { return (bool)GetValue(MyFocusProperty); } 65 | set { SetValue(MyFocusProperty, value); } 66 | } 67 | public static readonly DependencyProperty MyFocusProperty = 68 | DependencyProperty.Register("MyFocus", typeof(bool), typeof(TextBoxControl), 69 | new PropertyMetadata(true, new PropertyChangedCallback(TextBoxControl.OnMyFocusPropertyChanged))); 70 | 71 | private static void OnMyFocusPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 72 | { 73 | if (obj is TextBoxControl) 74 | { 75 | (obj as TextBoxControl).OnMyFocusValueChanged(); 76 | } 77 | } 78 | 79 | protected void OnMyFocusValueChanged() 80 | { 81 | if (!MyFocus) 82 | { 83 | if (string.IsNullOrEmpty(_TextBox.Text)) 84 | { 85 | MainWindow.RemoveControl(this); 86 | } 87 | else 88 | { 89 | MainWindow.Current.MainImage.ResetLimit(Canvas.GetLeft(this), Canvas.GetTop(this), (Canvas.GetLeft(this) + ActualWidth), (Canvas.GetTop(this) + ActualHeight)); 90 | MainWindow.Register(this); 91 | } 92 | MainWindow.Current.MainImage._Text = null; 93 | } 94 | } 95 | #endregion 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /ComeCapture/Controls/TextTool.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Media; 5 | 6 | namespace ComeCapture.Controls 7 | { 8 | public class TextTool : StackPanel 9 | { 10 | static TextTool() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(TextTool), new FrameworkPropertyMetadata(typeof(TextTool))); 13 | } 14 | 15 | public TextTool() 16 | { 17 | _Current = this; 18 | } 19 | 20 | #region 属性 Current 21 | private static TextTool _Current = null; 22 | public static TextTool Current 23 | { 24 | get 25 | { 26 | return _Current; 27 | } 28 | } 29 | #endregion 30 | 31 | #region 属性 FontSizes 32 | private static Dictionary _FontSizes; 33 | public static Dictionary FontSizes 34 | { 35 | get 36 | { 37 | if (_FontSizes == null) 38 | { 39 | _FontSizes = new Dictionary() 40 | { 41 | { 8,8}, 42 | { 10,10}, 43 | { 12,12}, 44 | { 14,14}, 45 | { 16,16}, 46 | { 18,18}, 47 | { 20,20}, 48 | { 22,22} 49 | }; 50 | } 51 | return _FontSizes; 52 | } 53 | set 54 | { 55 | _FontSizes = value; 56 | } 57 | } 58 | #endregion 59 | 60 | #region FontSize DependencyProperty 61 | public int FontSize 62 | { 63 | get { return (int)GetValue(FontSizeProperty); } 64 | set { SetValue(FontSizeProperty, value); } 65 | } 66 | public static readonly DependencyProperty FontSizeProperty = 67 | DependencyProperty.Register("FontSize", typeof(int), typeof(TextTool), 68 | new PropertyMetadata(12, new PropertyChangedCallback(TextTool.OnFontSizePropertyChanged))); 69 | 70 | private static void OnFontSizePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 71 | { 72 | if (obj is TextTool) 73 | { 74 | (obj as TextTool).OnFontSizeValueChanged(); 75 | } 76 | } 77 | 78 | protected void OnFontSizeValueChanged() 79 | { 80 | 81 | } 82 | #endregion 83 | 84 | #region LineBrush DependencyProperty 85 | public SolidColorBrush LineBrush 86 | { 87 | get { return (SolidColorBrush)GetValue(LineBrushProperty); } 88 | set { SetValue(LineBrushProperty, value); } 89 | } 90 | public static readonly DependencyProperty LineBrushProperty = 91 | DependencyProperty.Register("LineBrush", typeof(SolidColorBrush), typeof(TextTool), 92 | new PropertyMetadata(new SolidColorBrush(Colors.Red), new PropertyChangedCallback(TextTool.OnLineBrushPropertyChanged))); 93 | 94 | private static void OnLineBrushPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 95 | { 96 | if (obj is TextTool) 97 | { 98 | (obj as TextTool).OnLineBrushValueChanged(); 99 | } 100 | } 101 | 102 | protected void OnLineBrushValueChanged() 103 | { 104 | 105 | } 106 | #endregion 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /ComeCapture/Controls/ToolButton.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Models; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Media; 5 | 6 | namespace ComeCapture.Controls 7 | { 8 | public class ToolButton : RadioButton 9 | { 10 | static ToolButton() 11 | { 12 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ToolButton), new FrameworkPropertyMetadata(typeof(ToolButton))); 13 | } 14 | 15 | #region 覆写点击事件(可弹起) 16 | protected override void OnClick() 17 | { 18 | if (IsImageEditBar) 19 | { 20 | switch (Tool) 21 | { 22 | case Tool.Revoke: 23 | MainWindow.Current.OnRevoke(); 24 | break; 25 | case Tool.Save: 26 | MainWindow.Current.OnSave(); 27 | break; 28 | case Tool.Cancel: 29 | MainWindow.Current.OnCancel(); 30 | break; 31 | case Tool.OK: 32 | MainWindow.Current.OnOK(); 33 | break; 34 | default: 35 | IsChecked = !IsChecked; 36 | SizeColorBar.Current.Selected = IsChecked == true ? Tool : Tool.Null; 37 | break; 38 | } 39 | } 40 | else 41 | { 42 | if (IsChecked == false) 43 | { 44 | IsChecked = true; 45 | if (LineColor != null) 46 | { 47 | SizeColorBar.Current.ChangeColor(LineColor); 48 | } 49 | } 50 | } 51 | } 52 | #endregion 53 | 54 | #region Tool DependencyProperty 55 | public Tool Tool 56 | { 57 | get { return (Tool)GetValue(ToolProperty); } 58 | set { SetValue(ToolProperty, value); } 59 | } 60 | public static readonly DependencyProperty ToolProperty = 61 | DependencyProperty.Register("Tool", typeof(Tool), typeof(ToolButton), 62 | new PropertyMetadata(Tool.Null, new PropertyChangedCallback(ToolButton.OnToolPropertyChanged))); 63 | 64 | private static void OnToolPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 65 | { 66 | if (obj is ToolButton) 67 | { 68 | (obj as ToolButton).OnToolValueChanged(); 69 | } 70 | } 71 | 72 | protected void OnToolValueChanged() 73 | { 74 | 75 | } 76 | #endregion 77 | 78 | #region IsImageEditBar DependencyProperty 79 | public bool IsImageEditBar 80 | { 81 | get { return (bool)GetValue(IsImageEditBarProperty); } 82 | set { SetValue(IsImageEditBarProperty, value); } 83 | } 84 | public static readonly DependencyProperty IsImageEditBarProperty = 85 | DependencyProperty.Register("IsImageEditBar", typeof(bool), typeof(ToolButton), 86 | new PropertyMetadata(false, new PropertyChangedCallback(ToolButton.OnIsImageEditBarPropertyChanged))); 87 | 88 | private static void OnIsImageEditBarPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 89 | { 90 | if (obj is ToolButton) 91 | { 92 | (obj as ToolButton).OnIsImageEditBarValueChanged(); 93 | } 94 | } 95 | 96 | protected void OnIsImageEditBarValueChanged() 97 | { 98 | 99 | } 100 | #endregion 101 | 102 | #region LineColor DependencyProperty 103 | public SolidColorBrush LineColor 104 | { 105 | get { return (SolidColorBrush)GetValue(LineColorProperty); } 106 | set { SetValue(LineColorProperty, value); } 107 | } 108 | public static readonly DependencyProperty LineColorProperty = 109 | DependencyProperty.Register("LineColor", typeof(SolidColorBrush), typeof(ToolButton), 110 | new PropertyMetadata(null, new PropertyChangedCallback(ToolButton.OnLineColorPropertyChanged))); 111 | 112 | private static void OnLineColorPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 113 | { 114 | if (obj is ToolButton) 115 | { 116 | (obj as ToolButton).OnLineColorValueChanged(); 117 | } 118 | } 119 | 120 | protected void OnLineColorValueChanged() 121 | { 122 | 123 | } 124 | #endregion 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /ComeCapture/Controls/ZoomThumb.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Models; 2 | using System.Windows; 3 | using System.Windows.Controls.Primitives; 4 | 5 | namespace ComeCapture.Controls 6 | { 7 | public class ZoomThumb : Thumb 8 | { 9 | #region Direction DependencyProperty 10 | public Direction Direction 11 | { 12 | get { return (Direction)GetValue(DirectionProperty); } 13 | set { SetValue(DirectionProperty, value); } 14 | } 15 | public static readonly DependencyProperty DirectionProperty = 16 | DependencyProperty.Register("Direction", typeof(Direction), typeof(ZoomThumb), 17 | new PropertyMetadata(Direction.Null, new PropertyChangedCallback(ZoomThumb.OnDirectionPropertyChanged))); 18 | 19 | private static void OnDirectionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 20 | { 21 | if (obj is ZoomThumb) 22 | { 23 | (obj as ZoomThumb).OnDirectionValueChanged(); 24 | } 25 | } 26 | 27 | protected void OnDirectionValueChanged() 28 | { 29 | if (Direction == Direction.Move) 30 | { 31 | MouseDoubleClick += (sender, e) => 32 | { 33 | MainWindow.Current.OnOK(); 34 | }; 35 | } 36 | } 37 | #endregion 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ComeCapture/Converters/ColorConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Data; 3 | using System.Windows.Media; 4 | 5 | namespace ComeCapture.Converters 6 | { 7 | public class ColorConverter: IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 10 | { 11 | return new SolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString(value.ToString())); 12 | } 13 | 14 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 15 | { 16 | return null; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ComeCapture/Converters/SizeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Data; 3 | 4 | namespace ComeCapture.Converters 5 | { 6 | public class SizeConverter : IValueConverter 7 | { 8 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 9 | { 10 | return int.Parse(value.ToString()) == int.Parse(parameter.ToString()); 11 | } 12 | 13 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 14 | { 15 | if ((bool)value) 16 | { 17 | return parameter; 18 | } 19 | else 20 | { 21 | return null; 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ComeCapture/Converters/ToolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Data; 4 | 5 | namespace ComeCapture.Converters 6 | { 7 | public class ToolConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 10 | { 11 | return value.ToString() == parameter.ToString() ? Visibility.Visible : Visibility.Collapsed; 12 | } 13 | 14 | public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 15 | { 16 | return null; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ComeCapture/Helpers/ImageHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Imaging; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Interop; 7 | using System.Windows.Media.Imaging; 8 | 9 | namespace ComeCapture.Helpers 10 | { 11 | public class ImageHelper 12 | { 13 | #region 保存为PNG图片 14 | public static void SaveToPng(BitmapSource image, string fileName) 15 | { 16 | using (var fs = System.IO.File.Create(fileName)) 17 | { 18 | BitmapEncoder encoder = new PngBitmapEncoder(); 19 | encoder.Frames.Add(BitmapFrame.Create(image)); 20 | encoder.Save(fs); 21 | } 22 | } 23 | #endregion 24 | 25 | #region 截图 26 | public static BitmapSource GetBitmapSource(int x, int y, int width, int height) 27 | { 28 | var bounds = ScreenHelper.GetPhysicalDisplaySize(); 29 | var screenWidth = bounds.Width; 30 | var screenHeight = bounds.Height; 31 | var scaleWidth = (screenWidth * 1.0) / SystemParameters.PrimaryScreenWidth; 32 | var scaleHeight = (screenHeight * 1.0) / SystemParameters.PrimaryScreenHeight; 33 | var w = (int)(width * scaleWidth); 34 | var h = (int)(height * scaleHeight); 35 | var l = (int)(x * scaleWidth); 36 | var t = (int)(y * scaleHeight); 37 | using (var bm = new Bitmap(w, h, PixelFormat.Format32bppArgb)) 38 | { 39 | using (var g = Graphics.FromImage(bm)) 40 | { 41 | g.CopyFromScreen(l, t, 0, 0, bm.Size); 42 | return Imaging.CreateBitmapSourceFromHBitmap( 43 | bm.GetHbitmap(), 44 | IntPtr.Zero, 45 | Int32Rect.Empty, 46 | BitmapSizeOptions.FromEmptyOptions()); 47 | } 48 | } 49 | } 50 | #endregion 51 | 52 | #region 全屏截图 53 | public static BitmapSource GetFullBitmapSource() 54 | { 55 | var bounds = ScreenHelper.GetPhysicalDisplaySize(); 56 | _Bitmap = new Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); 57 | var bmpGraphics = Graphics.FromImage(_Bitmap); 58 | bmpGraphics.CopyFromScreen(0, 0, 0, 0, _Bitmap.Size); 59 | return Imaging.CreateBitmapSourceFromHBitmap( 60 | _Bitmap.GetHbitmap(), 61 | IntPtr.Zero, 62 | Int32Rect.Empty, 63 | BitmapSizeOptions.FromEmptyOptions()); 64 | } 65 | #endregion 66 | 67 | #region 获取RGB 68 | private static Bitmap _Bitmap = null; 69 | private static StringBuilder sb = new StringBuilder(); 70 | public static string GetRGB(int x,int y) 71 | { 72 | var color = _Bitmap.GetPixel(x, y); 73 | sb.Clear(); 74 | sb.Append("RGB:("); 75 | sb.Append(color.R.ToString()); 76 | sb.Append(","); 77 | sb.Append(color.G.ToString()); 78 | sb.Append(","); 79 | sb.Append(color.B.ToString()); 80 | sb.Append(")"); 81 | return sb.ToString(); 82 | } 83 | #endregion 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ComeCapture/Helpers/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * author : singba singba@163.com 3 | * version : 20161221 4 | * source : AF.Wpf 5 | * license : free use or modify 6 | * description : WPF的按钮命令的基类,本程序根据微软WPF例子中的RelayCommmand做了些扩展封装 7 | */ 8 | using System; 9 | using System.Windows.Input; 10 | 11 | namespace ComeCapture.Helpers 12 | { 13 | /// 14 | /// 界面命令类 15 | /// 16 | public class RelayCommand : ICommand 17 | { 18 | #region Fields 19 | 20 | private Func _canExecute; 21 | private Action _execute; 22 | private bool _IsExecuting = false; 23 | #endregion // Fields 24 | 25 | #region Constructors 26 | 27 | public RelayCommand(Action execute) 28 | : this(execute, null) 29 | { 30 | } 31 | 32 | public RelayCommand(Action execute, Func canExecute) 33 | { 34 | ResetActions(execute, canExecute); 35 | } 36 | 37 | #endregion // Constructors 38 | 39 | //特殊情况下方法需要重设 40 | 41 | #region ICommand Members 42 | 43 | public bool CanExecute(object parameter) 44 | { 45 | return _canExecute == null ? true : ((!_IsExecuting) && _canExecute(parameter)); 46 | } 47 | 48 | public event EventHandler CanExecuteChanged 49 | { 50 | add { System.Windows.Input.CommandManager.RequerySuggested += value; } 51 | remove { System.Windows.Input.CommandManager.RequerySuggested -= value; } 52 | } 53 | 54 | public void Execute(object parameter) 55 | { 56 | try 57 | { 58 | if (_IsExecuting) 59 | return; 60 | _IsExecuting = true; 61 | RaiseCanExecuteChanged(); 62 | _execute(parameter); 63 | } 64 | catch (Exception) 65 | { 66 | throw; 67 | } 68 | finally 69 | { 70 | _IsExecuting = false; 71 | RaiseCanExecuteChanged(); 72 | } 73 | } 74 | 75 | #endregion 76 | 77 | public void ResetActions(Action execute, Func canExecute) 78 | { 79 | if (execute != null) 80 | { 81 | _execute = execute; 82 | } 83 | if (canExecute != null) 84 | { 85 | _canExecute = canExecute; 86 | } 87 | } 88 | 89 | public void RaiseCanExecuteChanged() 90 | { 91 | CommandManager.InvalidateRequerySuggested(); 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /ComeCapture/Helpers/ScreenHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace ComeCapture.Helpers 6 | { 7 | public static class ScreenHelper 8 | { 9 | [DllImport("user32.dll", EntryPoint = "ReleaseDC")] 10 | public static extern IntPtr ReleaseDC( 11 | IntPtr hWnd, 12 | IntPtr hDc 13 | ); 14 | 15 | [DllImport("gdi32.dll")] 16 | public static extern int GetDeviceCaps( 17 | IntPtr hdc, // handle to DC 18 | int nIndex // index of capability 19 | ); 20 | 21 | public static System.Drawing.Size GetPhysicalDisplaySize() 22 | { 23 | Graphics g = Graphics.FromHwnd(IntPtr.Zero); 24 | IntPtr desktop = g.GetHdc(); 25 | int physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.Desktopvertres); 26 | int physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres); 27 | ReleaseDC(IntPtr.Zero, desktop); 28 | g.Dispose(); 29 | return new System.Drawing.Size(physicalScreenWidth, physicalScreenHeight); 30 | } 31 | 32 | public enum DeviceCap 33 | { 34 | Desktopvertres = 117, 35 | Desktophorzres = 118 36 | } 37 | 38 | public static void ResetScreenScale() 39 | { 40 | using (var g = Graphics.FromHwnd(IntPtr.Zero)) 41 | { 42 | IntPtr desktop = g.GetHdc(); 43 | int physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres); 44 | MainWindow.ScreenScale = physicalScreenWidth * 1.0000 / MainWindow.ScreenWidth; 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ComeCapture/Helpers/WpfHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Threading; 3 | 4 | namespace ComeCapture.Helpers 5 | { 6 | public static class WpfHelper 7 | { 8 | public static Dispatcher MainDispatcher { get; set; } 9 | public static void SafeRun(this Action action) 10 | { 11 | if (MainDispatcher == null) 12 | { 13 | action(); 14 | return; 15 | } 16 | 17 | if (!MainDispatcher.CheckAccess()) 18 | { 19 | MainDispatcher.BeginInvoke(action); 20 | return; 21 | } 22 | action(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ComeCapture/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /ComeCapture/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Controls; 2 | using ComeCapture.Helpers; 3 | using ComeCapture.Models; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | 13 | namespace ComeCapture 14 | { 15 | /// 16 | /// MainWindow.xaml 的交互逻辑 17 | /// 18 | public partial class MainWindow : Window 19 | { 20 | public static double ScreenWidth = SystemParameters.PrimaryScreenWidth; 21 | public static double ScreenHeight = SystemParameters.PrimaryScreenHeight; 22 | public static double ScreenScale = 1; 23 | public static int MinSize = 10; 24 | 25 | //画图注册名称集合 26 | public List list = new List(); 27 | //画图注册名称 28 | public int num = 1; 29 | 30 | //是否截图开始 31 | private bool _IsMouseDown = false; 32 | //是否截图完毕 33 | private bool _IsCapture = false; 34 | 35 | private double _X0 = 0; 36 | private double _Y0 = 0; 37 | 38 | public MainWindow() 39 | { 40 | _Current = this; 41 | InitializeComponent(); 42 | DataContext = new AppModel(); 43 | Background = new ImageBrush(ImageHelper.GetFullBitmapSource()); 44 | WpfHelper.MainDispatcher = Dispatcher; 45 | MaxWindow(); 46 | MaskLeft.Height = ScreenHeight; 47 | MaskRight.Height = ScreenHeight; 48 | //计算Windows项目缩放比例 49 | ScreenHelper.ResetScreenScale(); 50 | } 51 | 52 | #region 属性 Current 53 | private static MainWindow _Current = null; 54 | public static MainWindow Current 55 | { 56 | get 57 | { 58 | return _Current; 59 | } 60 | } 61 | #endregion 62 | 63 | #region 全屏+置顶 64 | private void MaxWindow() 65 | { 66 | Left = 0; 67 | Top = 0; 68 | Width = ScreenWidth; 69 | Height = ScreenHeight; 70 | Activate(); 71 | } 72 | #endregion 73 | 74 | #region 注册画图 75 | public static void Register(object control) 76 | { 77 | var name = "Draw" + _Current.num; 78 | _Current.MainCanvas.RegisterName(name, control); 79 | _Current.list.Add(new NameAndLimit(name)); 80 | _Current.num++; 81 | } 82 | #endregion 83 | 84 | #region 截图区域添加画图 85 | public static void AddControl(UIElement e) 86 | { 87 | _Current.MainCanvas.Children.Add(e); 88 | } 89 | #endregion 90 | 91 | #region 截图区域撤回画图 92 | public static void RemoveControl(UIElement e) 93 | { 94 | _Current.MainCanvas.Children.Remove(e); 95 | } 96 | #endregion 97 | 98 | #region 撤销 99 | public void OnRevoke() 100 | { 101 | if (list.Count > 0) 102 | { 103 | var name = list[list.Count - 1].Name; 104 | var obj = MainCanvas.FindName(name); 105 | if (obj != null) 106 | { 107 | MainCanvas.Children.Remove(obj as UIElement); 108 | MainCanvas.UnregisterName(name); 109 | list.RemoveAt(list.Count - 1); 110 | MainImage.Limit = list.Count == 0 ? new Limit() : list[list.Count - 1].Limit; 111 | } 112 | } 113 | } 114 | #endregion 115 | 116 | #region 保存 117 | public void OnSave() 118 | { 119 | var sfd = new Microsoft.Win32.SaveFileDialog 120 | { 121 | FileName = "截图" + DateTime.Now.ToString("yyyyMMddhhmmss"), 122 | Filter = "png|*.png", 123 | AddExtension = true, 124 | RestoreDirectory = true 125 | }; 126 | if (sfd.ShowDialog() == true) 127 | { 128 | Hidden(); 129 | Thread t = new Thread(new ThreadStart(() => 130 | { 131 | Thread.Sleep(200); 132 | WpfHelper.SafeRun(() => 133 | { 134 | var source = GetCapture(); 135 | if (source != null) 136 | { 137 | ImageHelper.SaveToPng(source, sfd.FileName); 138 | } 139 | Close(); 140 | }); 141 | })) 142 | { 143 | IsBackground = true 144 | }; 145 | t.Start(); 146 | } 147 | } 148 | #endregion 149 | 150 | #region 获取截图 151 | private BitmapSource GetCapture() 152 | { 153 | return ImageHelper.GetBitmapSource((int)AppModel.Current.MaskLeftWidth + 1, (int)AppModel.Current.MaskTopHeight + 1, (int)MainImage.ActualWidth - 2, (int)MainImage.ActualHeight - 2); ; 154 | } 155 | #endregion 156 | 157 | #region 退出截图 158 | public void OnCancel() 159 | { 160 | Close(); 161 | } 162 | #endregion 163 | 164 | #region 完成截图 165 | public void OnOK() 166 | { 167 | Hidden(); 168 | Thread t = new Thread(new ThreadStart(() => 169 | { 170 | Thread.Sleep(50); 171 | WpfHelper.SafeRun(() => 172 | { 173 | var source = GetCapture(); 174 | if (source != null) 175 | { 176 | Clipboard.SetImage(source); 177 | } 178 | Close(); 179 | }); 180 | })) 181 | { 182 | IsBackground = true 183 | }; 184 | t.Start(); 185 | } 186 | #endregion 187 | 188 | #region 截图前隐藏窗口 189 | private void Hidden() 190 | { 191 | //隐藏尺寸RGB框 192 | if (AppModel.Current.MaskTopHeight < 40) 193 | { 194 | SizeRGB.Visibility = Visibility.Collapsed; 195 | } 196 | var need = SizeColorBar.Current.Selected == Tool.Null ? 30 : 67; 197 | if (AppModel.Current.MaskBottomHeight < need && AppModel.Current.MaskTopHeight < need) 198 | { 199 | ImageEditBar.Current.Visibility = Visibility.Collapsed; 200 | SizeColorBar.Current.Visibility = Visibility.Collapsed; 201 | } 202 | MainImage.ZoomThumbVisibility = Visibility.Collapsed; 203 | } 204 | #endregion 205 | 206 | #region 鼠标及键盘事件 207 | private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 208 | { 209 | if (_IsCapture) 210 | { 211 | return; 212 | } 213 | var point = e.GetPosition(this); 214 | _X0 = point.X; 215 | _Y0 = point.Y; 216 | _IsMouseDown = true; 217 | Canvas.SetLeft(MainImage, _X0); 218 | Canvas.SetTop(MainImage, _Y0); 219 | AppModel.Current.MaskLeftWidth = _X0; 220 | AppModel.Current.MaskRightWidth = ScreenWidth - _X0; 221 | AppModel.Current.MaskTopHeight = _Y0; 222 | Show_Size.Visibility = Visibility.Visible; 223 | } 224 | 225 | private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 226 | { 227 | if (!_IsMouseDown || _IsCapture) 228 | { 229 | return; 230 | } 231 | _IsMouseDown = false; 232 | if (MainImage.Width >= MinSize && MainImage.Height >= MinSize) 233 | { 234 | _IsCapture = true; 235 | ImageEditBar.Current.Visibility = Visibility.Visible; 236 | ImageEditBar.Current.ResetCanvas(); 237 | Cursor = Cursors.Arrow; 238 | } 239 | } 240 | 241 | private void Window_MouseMove(object sender, MouseEventArgs e) 242 | { 243 | var point = e.GetPosition(this); 244 | var screenP = PointToScreen(point); 245 | AppModel.Current.ShowRGB = ImageHelper.GetRGB((int)screenP.X, (int)screenP.Y); 246 | if (_IsCapture) 247 | { 248 | return; 249 | } 250 | 251 | if (Show_RGB.Visibility == Visibility.Collapsed) 252 | { 253 | Show_RGB.Visibility = Visibility.Visible; 254 | } 255 | 256 | if (_IsMouseDown) 257 | { 258 | var w = point.X - _X0; 259 | var h = point.Y - _Y0; 260 | if (w < MinSize || h < MinSize) 261 | { 262 | return; 263 | } 264 | if (MainImage.Visibility == Visibility.Collapsed) 265 | { 266 | MainImage.Visibility = Visibility.Visible; 267 | } 268 | AppModel.Current.MaskRightWidth = ScreenWidth - point.X; 269 | AppModel.Current.MaskTopWidth = w; 270 | AppModel.Current.MaskBottomHeight = ScreenHeight - point.Y; 271 | AppModel.Current.ChangeShowSize(); 272 | MainImage.Width = w; 273 | MainImage.Height = h; 274 | } 275 | else 276 | { 277 | AppModel.Current.ShowSizeLeft = point.X; 278 | AppModel.Current.ShowSizeTop = ScreenHeight - point.Y < 30 ? point.Y - 30 : point.Y + 10; 279 | } 280 | } 281 | 282 | private void Window_KeyDown(object sender, KeyEventArgs e) 283 | { 284 | if (e.Key == Key.Escape) 285 | { 286 | Close(); 287 | } 288 | } 289 | #endregion 290 | 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /ComeCapture/Models/AppModel.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Helpers; 2 | using ComeCapture.Models; 3 | using System.Text; 4 | 5 | namespace ComeCapture 6 | { 7 | public class AppModel : EntityBase 8 | { 9 | public AppModel() 10 | { 11 | _Current = this; 12 | } 13 | 14 | #region 属性 Current 15 | private static AppModel _Current = null; 16 | public static AppModel Current 17 | { 18 | get 19 | { 20 | return _Current; 21 | } 22 | } 23 | #endregion 24 | 25 | #region 属性 MaskLeftWidth 26 | private double _MaskLeftWidth = MainWindow.ScreenWidth; 27 | public double MaskLeftWidth 28 | { 29 | get 30 | { 31 | return _MaskLeftWidth; 32 | } 33 | set 34 | { 35 | _MaskLeftWidth = value; 36 | ShowSizeLeft = value; 37 | RaisePropertyChanged(() => MaskLeftWidth); 38 | } 39 | } 40 | #endregion 41 | 42 | #region 属性 MaskRightWidth 43 | private double _MaskRightWidth = 0; 44 | public double MaskRightWidth 45 | { 46 | get 47 | { 48 | return _MaskRightWidth; 49 | } 50 | set 51 | { 52 | _MaskRightWidth = value; 53 | RaisePropertyChanged(() => MaskRightWidth); 54 | } 55 | } 56 | #endregion 57 | 58 | #region 属性 MaskTopWidth 59 | private double _MaskTopWidth = 0; 60 | public double MaskTopWidth 61 | { 62 | get 63 | { 64 | return _MaskTopWidth; 65 | } 66 | set 67 | { 68 | _MaskTopWidth = value; 69 | RaisePropertyChanged(() => MaskTopWidth); 70 | } 71 | } 72 | #endregion 73 | 74 | #region 属性 MaskTopHeight 75 | private double _MaskTopHeight = 0; 76 | public double MaskTopHeight 77 | { 78 | get 79 | { 80 | return _MaskTopHeight; 81 | } 82 | set 83 | { 84 | _MaskTopHeight = value; 85 | ShowSizeTop = MaskTopHeight < 40 ? MaskTopHeight : MaskTopHeight - 40; 86 | RaisePropertyChanged(() => MaskTopHeight); 87 | } 88 | } 89 | #endregion 90 | 91 | #region 属性 MaskBottomHeight 92 | private double _MaskBottomHeight = 0; 93 | public double MaskBottomHeight 94 | { 95 | get 96 | { 97 | return _MaskBottomHeight; 98 | } 99 | set 100 | { 101 | _MaskBottomHeight = value; 102 | RaisePropertyChanged(() => MaskBottomHeight); 103 | } 104 | } 105 | #endregion 106 | 107 | #region 属性 ShowSize 108 | private string _ShowSize = "0 × 0"; 109 | public string ShowSize 110 | { 111 | get 112 | { 113 | return _ShowSize; 114 | } 115 | set 116 | { 117 | _ShowSize = value; 118 | RaisePropertyChanged(() => ShowSize); 119 | } 120 | } 121 | 122 | private static StringBuilder sb = new StringBuilder(); 123 | public void ChangeShowSize() 124 | { 125 | sb.Clear(); 126 | sb.Append((int)(MainWindow.Current.MainImage.Width * MainWindow.ScreenScale)); 127 | sb.Append(" × "); 128 | sb.Append((int)(MainWindow.Current.MainImage.Height * MainWindow.ScreenScale)); 129 | ShowSize = sb.ToString(); 130 | } 131 | #endregion 132 | 133 | #region 属性 ShowSizeLeft 134 | private double _ShowSizeLeft = 0; 135 | public double ShowSizeLeft 136 | { 137 | get 138 | { 139 | return _ShowSizeLeft; 140 | } 141 | set 142 | { 143 | _ShowSizeLeft = value; 144 | RaisePropertyChanged(() => ShowSizeLeft); 145 | } 146 | } 147 | #endregion 148 | 149 | #region 属性 ShowSizeTop 150 | private double _ShowSizeTop = 0; 151 | public double ShowSizeTop 152 | { 153 | get 154 | { 155 | return _ShowSizeTop; 156 | } 157 | set 158 | { 159 | _ShowSizeTop = value; 160 | RaisePropertyChanged(() => ShowSizeTop); 161 | } 162 | } 163 | #endregion 164 | 165 | #region 属性 ShowRGB 166 | private string _ShowRGB = string.Empty; 167 | public string ShowRGB 168 | { 169 | get 170 | { 171 | return _ShowRGB; 172 | } 173 | set 174 | { 175 | _ShowRGB = value; 176 | RaisePropertyChanged(() => ShowRGB); 177 | } 178 | } 179 | #endregion 180 | 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /ComeCapture/Models/Direction.cs: -------------------------------------------------------------------------------- 1 | namespace ComeCapture.Models 2 | { 3 | public enum Direction 4 | { 5 | Null = 0, 6 | Move = 1, 7 | LeftTop = 2, 8 | LeftMiddle = 3, 9 | LeftBottom = 4, 10 | MiddleTop = 5, 11 | MiddleBottom = 6, 12 | RightTop = 7, 13 | RightMiddle = 8, 14 | RightBottom = 9 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ComeCapture/Models/EntityBase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * author : singba singba@163.com 3 | * version : 20161221 4 | * source : AF.Core 5 | * license : free use or modify 6 | * description : 通用类型基类 7 | */ 8 | using System; 9 | using System.Linq.Expressions; 10 | 11 | namespace ComeCapture.Models 12 | { 13 | /// 14 | /// singba:20120807 15 | /// 这个基类只作为INotifyPropertyChanged的实现,不再是Entity的基类 16 | /// 17 | public class EntityBase : System.ComponentModel.INotifyPropertyChanged 18 | { 19 | #region INotifyPropertyChanged Members 20 | public virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; 21 | 22 | protected virtual void RaisePropertyChanged(string name) 23 | { 24 | if (PropertyChanged != null) 25 | { 26 | PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(name)); 27 | } 28 | } 29 | 30 | protected virtual void RaisePropertyChanged(Expression> property) 31 | { 32 | var lambda = (LambdaExpression)property; 33 | MemberExpression memberExpression; 34 | if (lambda.Body is UnaryExpression) 35 | { 36 | var unaryExpression = (UnaryExpression)lambda.Body; 37 | memberExpression = (MemberExpression)unaryExpression.Operand; 38 | } 39 | else memberExpression = (MemberExpression)lambda.Body; 40 | RaisePropertyChanged(memberExpression.Member.Name); 41 | } 42 | #endregion 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ComeCapture/Models/Limit.cs: -------------------------------------------------------------------------------- 1 | using ComeCapture.Controls; 2 | 3 | namespace ComeCapture.Models 4 | { 5 | /// 6 | /// 图片移动的极限值 7 | /// 8 | public class Limit 9 | { 10 | public double Left { get; set; } = MainWindow.ScreenWidth; 11 | public double Right { get; set; } = 0; 12 | public double Top { get; set; } = MainWindow.ScreenHeight; 13 | public double Bottom { get; set; } = 0; 14 | 15 | public Limit Clone() 16 | { 17 | return MemberwiseClone() as Limit; 18 | } 19 | 20 | public Limit() 21 | { 22 | 23 | } 24 | } 25 | 26 | /// 27 | /// 注册名称以及对应图片极限值 28 | /// 29 | public class NameAndLimit 30 | { 31 | public string Name { get; set; } 32 | public Limit Limit { get; set; } 33 | 34 | public NameAndLimit(string name) 35 | { 36 | Name = name; 37 | Limit = MainWindow.Current.MainImage.Limit.Clone(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ComeCapture/Models/Tool.cs: -------------------------------------------------------------------------------- 1 | namespace ComeCapture.Models 2 | { 3 | public enum Tool 4 | { 5 | Null,//无状态可移动 6 | Rectangle,//长方形 7 | Ellipse,//圆形 8 | Line,//画刷 9 | Text,//文字 10 | Arrow,//箭头 11 | Revoke,//撤销 12 | Save,//保存 13 | Cancel,//退出截图 14 | OK//完成截图 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ComeCapture/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // 有关程序集的一般信息由以下 8 | // 控制。更改这些特性值可修改 9 | // 与程序集关联的信息。 10 | [assembly: AssemblyTitle("ComeCapture")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("ComeCapture")] 15 | [assembly: AssemblyCopyright("Copyright © 2017")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // 将 ComVisible 设置为 false 会使此程序集中的类型 20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 21 | //请将此类型的 ComVisible 特性设置为 true。 22 | [assembly: ComVisible(false)] 23 | 24 | //若要开始生成可本地化的应用程序,请设置 25 | //.csproj 文件中的 CultureYouAreCodingWith 26 | //例如,如果您在源文件中使用的是美国英语, 27 | //使用的是美国英语,请将 设置为 en-US。 然后取消 28 | //对以下 NeutralResourceLanguage 特性的注释。 更新 29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 36 | //(未在页面中找到资源时使用, 37 | //或应用程序资源字典中找到时使用) 38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 39 | //(未在页面中找到资源时使用, 40 | //、应用程序或任何主题专用资源字典中找到时使用) 41 | )] 42 | 43 | 44 | // 程序集的版本信息由下列四个值组成: 45 | // 46 | // 主版本 47 | // 次版本 48 | // 生成号 49 | // 修订号 50 | // 51 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 52 | // 方法是按如下所示使用“*”: : 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /ComeCapture/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ScreenCapture.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | public class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | public static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ScreenCapture.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 使用此强类型资源类,为所有资源查找 51 | /// 重写当前线程的 CurrentUICulture 属性。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | public static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ComeCapture/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /ComeCapture/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ComeCapture.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ComeCapture/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /ComeCapture/Resources/cut.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/cut.ico -------------------------------------------------------------------------------- /ComeCapture/Resources/showyou.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/showyou.png -------------------------------------------------------------------------------- /ComeCapture/Resources/保存.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/保存.png -------------------------------------------------------------------------------- /ComeCapture/Resources/后退.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/后退.png -------------------------------------------------------------------------------- /ComeCapture/Resources/笔刷.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/笔刷.png -------------------------------------------------------------------------------- /ComeCapture/Resources/箭头.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/箭头.png -------------------------------------------------------------------------------- /ComeCapture/Resources/设置.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/Resources/设置.png -------------------------------------------------------------------------------- /ComeCapture/Themes/Generic.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 2 14 | 5 15 | 8 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 32 | 33 | 34 | 45 | 46 | 47 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 107 | 108 | 109 | 116 | 117 | 118 | 123 | 124 | 125 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 206 | 207 | 208 | 215 | 216 | 217 | 226 | 227 | 228 | 241 | 242 | 243 | 385 | 386 | 387 | 421 | 422 | 423 | -------------------------------------------------------------------------------- /ComeCapture/cut.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SeaSharpGit/ComeCapture/2e038265a6b6212e4d7aaf689d689bac2418c41f/ComeCapture/cut.ico -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

  ComeCapture

2 |

Description:ComeCapture is a screen capture project using WPF

3 | 4 | --------------------------------------------------------------------------------