├── .gitignore ├── .vs ├── Screenshots │ └── v16 │ │ └── .suo ├── VSWorkspaceState.json ├── slnx.sqlite └── 小小截图OCR │ └── v16 │ └── .suo ├── README.md ├── imgs ├── 1.png ├── 2.png └── 3.png ├── packages ├── Newtonsoft.Json.11.0.1 │ ├── .signature.p7s │ ├── LICENSE.md │ ├── Newtonsoft.Json.11.0.1.nupkg │ └── lib │ │ ├── net20 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── net35 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── net40 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── net45 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── netstandard1.0 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── netstandard1.3 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── netstandard2.0 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ ├── portable-net40+sl5+win8+wp8+wpa81 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml │ │ └── portable-net45+win8+wp8+wpa81 │ │ ├── Newtonsoft.Json.dll │ │ └── Newtonsoft.Json.xml ├── System.Text.Encodings.Web.4.5.1 │ ├── .signature.p7s │ ├── LICENSE.TXT │ ├── System.Text.Encodings.Web.4.5.1.nupkg │ ├── THIRD-PARTY-NOTICES.TXT │ ├── lib │ │ ├── netstandard1.0 │ │ │ ├── System.Text.Encodings.Web.dll │ │ │ └── System.Text.Encodings.Web.xml │ │ └── netstandard2.0 │ │ │ ├── System.Text.Encodings.Web.dll │ │ │ └── System.Text.Encodings.Web.xml │ ├── useSharedDesignerContext.txt │ └── version.txt ├── System.ValueTuple.4.3.0 │ ├── .signature.p7s │ ├── System.ValueTuple.4.3.0.nupkg │ ├── ThirdPartyNotices.txt │ ├── dotnet_library_license.txt │ └── lib │ │ ├── netstandard1.0 │ │ ├── .xml │ │ └── System.ValueTuple.dll │ │ └── portable-net40+sl4+win8+wp8 │ │ ├── .xml │ │ └── System.ValueTuple.dll └── TencentCloudSDK.3.0.308 │ ├── .signature.p7s │ ├── TencentCloudSDK.3.0.308.nupkg │ └── lib │ ├── net45 │ └── TencentCloud.dll │ └── netstandard2.0 │ └── TencentCloud.dll ├── 小小截图 └── 小小截图.vdproj ├── 小小截图OCR.sln └── 小小截图OCR ├── AcceptSelectEventArgs.cs ├── AcceptSelectHandler.cs ├── App.config ├── App.xaml ├── App.xaml.cs ├── Base64.cs ├── Command.cs ├── CursorInfo.cs ├── HotKey.cs ├── HotKeyRegisterFailException.cs ├── ISelector.cs ├── ImageEditor.cs ├── Keys.cs ├── Lisp.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── OcrTools.cs ├── PixelObserver.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── SelectState.cs ├── SelectorEventRegister.cs ├── TestWindow.xaml ├── TestWindow.xaml.cs ├── Themes └── Generic.xaml ├── Tip.cs ├── Tool.cs ├── ai41s-wdwmm-002.ico ├── config.ini ├── obj ├── Debug │ ├── .NETFramework,Version=v4.6.1.AssemblyAttributes.cs │ ├── .NETFramework,Version=v4.7.1.AssemblyAttributes.cs │ ├── App.g.cs │ ├── App.g.i.cs │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── GeneratedInternalTypeHelper.g.cs │ ├── GeneratedInternalTypeHelper.g.i.cs │ ├── Interop.IWshRuntimeLibrary.dll │ ├── MainWindow.baml │ ├── MainWindow.g.cs │ ├── MainWindow.g.i.cs │ ├── TempPE │ │ └── Properties.Resources.Designer.cs.dll │ ├── TestWindow.baml │ ├── TestWindow.g.cs │ ├── TestWindow.g.i.cs │ ├── Themes │ │ └── Generic.baml │ ├── Wpf截图工具.csproj.AssemblyReference.cache │ ├── Wpf截图工具_MarkupCompile.cache │ ├── Wpf截图工具_MarkupCompile.i.cache │ ├── Wpf截图工具_MarkupCompile.lref │ ├── 小小截图OCR.Properties.Resources.resources │ ├── 小小截图OCR.csproj.AssemblyReference.cache │ ├── 小小截图OCR.csproj.CopyComplete │ ├── 小小截图OCR.csproj.CoreCompileInputs.cache │ ├── 小小截图OCR.csproj.FileListAbsolute.txt │ ├── 小小截图OCR.csproj.GenerateResource.cache │ ├── 小小截图OCR.csproj.ResolveComReference.cache │ ├── 小小截图OCR.exe │ ├── 小小截图OCR.exe.config │ ├── 小小截图OCR.g.resources │ ├── 小小截图OCR.pdb │ ├── 小小截图OCR_Content.g.cs │ ├── 小小截图OCR_Content.g.i.cs │ ├── 小小截图OCR_MarkupCompile.cache │ ├── 小小截图OCR_MarkupCompile.i.cache │ └── 小小截图OCR_MarkupCompile.lref └── Release │ ├── .NETFramework,Version=v4.6.1.AssemblyAttributes.cs │ ├── .NETFramework,Version=v4.7.1.AssemblyAttributes.cs │ ├── App.g.cs │ ├── App.g.i.cs │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── GeneratedInternalTypeHelper.g.cs │ ├── GeneratedInternalTypeHelper.g.i.cs │ ├── Interop.IWshRuntimeLibrary.dll │ ├── MainWindow.baml │ ├── MainWindow.g.cs │ ├── MainWindow.g.i.cs │ ├── TempPE │ └── Properties.Resources.Designer.cs.dll │ ├── TestWindow.baml │ ├── TestWindow.g.cs │ ├── TestWindow.g.i.cs │ ├── Themes │ └── Generic.baml │ ├── Wpf截图工具_MarkupCompile.cache │ ├── Wpf截图工具_MarkupCompile.lref │ ├── 小小截图OCR.Properties.Resources.resources │ ├── 小小截图OCR.csproj.CopyComplete │ ├── 小小截图OCR.csproj.CoreCompileInputs.cache │ ├── 小小截图OCR.csproj.FileListAbsolute.txt │ ├── 小小截图OCR.csproj.GenerateResource.cache │ ├── 小小截图OCR.csproj.ResolveComReference.cache │ ├── 小小截图OCR.exe │ ├── 小小截图OCR.exe.config │ ├── 小小截图OCR.g.resources │ ├── 小小截图OCR.pdb │ ├── 小小截图OCR_Content.g.cs │ ├── 小小截图OCR_Content.g.i.cs │ ├── 小小截图OCR_MarkupCompile.cache │ └── 小小截图OCR_MarkupCompile.lref ├── packages.config ├── temp.txt ├── 小小截图OCR.csproj └── 小小截图OCR.csproj.user /.gitignore: -------------------------------------------------------------------------------- 1 | 小小截图/Debug/* 2 | 小小截图/Release/* 3 | 小小截图OCR/bin/* -------------------------------------------------------------------------------- /.vs/Screenshots/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/.vs/Screenshots/v16/.suo -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "" 4 | ], 5 | "SelectedNode": "\\C:\\Users\\lei\\Source\\Repos\\Screenshots", 6 | "PreviewInSolutionExplorer": false 7 | } -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/.vs/slnx.sqlite -------------------------------------------------------------------------------- /.vs/小小截图OCR/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/.vs/小小截图OCR/v16/.suo -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## windows轻量级工具 = 截图 + 文字识别 + 取色器 2 | 3 | ### 特点: 4 | 1. 轻量级,内存占用仅20MB,不截图时CPU占用为0%,截图时占用在1~3%; 5 | 2. **用户无感知(设计初衷)**, 6 | * 截图功能不管是QQ还是微信都有,但是每次截图或者文字识别都要打开QQ,然后登录,然后等消息和弹窗弹弹弹,然后再开始截图,十几秒过去了,体验极差,而该软件只需要瞬间; 7 | * 无窗口,无托盘,不会占用屏幕任何一块地方,用户不必在意或者知道它的存在,只需像系统本来就自带的软件使用即可(设计目的亦如此,像使用系统原生功能一样使用它); 8 | 3. 增加了取色器功能,取色器也是前端和UI设计时常用的功能; 9 | 10 | 11 | 12 | ### 功能说明: 13 | 14 | ### 唤出快捷键为 alt + a 15 | 16 | ![](./imgs/1.png) 17 | 18 | #### 1.快捷截图 19 | 20 | * 选择完截图区域后,双击所选截图区域的左上角区域将**图片复制到剪贴板** 21 | * 双击所截图区域的左下角区域将图片**保存至桌面**; 22 | 23 | #### 2.文字识别 24 | 25 | * 双击所选截图区域的右上角区域进行**通用文字识别** 26 | * 双击所选截图区域的右下角区域进行**手写体文字识别** 27 | 28 | #### 3.取色 29 | 30 | * 使用alt + a唤出截图软件后,鼠标移动的位置会自动显示rgb值 31 | 32 | #### 4.取消截图or重新选择截图区域 33 | * 在你当前选择的截图区域外单机右键即可重新选择截图区域 34 | * 再单击右键即可退出截图; 35 | 36 | 37 | 38 | ### 使用说明 39 | ===========================**直接使用**=========================== 40 | 41 | 1. 从Release中下载msi文件,双击安装; 42 | 43 | ![](./imgs/2.png) 44 | 45 | 2. 安装完成后,进入你的安装目录(默认为:C:\Program Files (x86)\Default Company Name\小小截图\),将config.ini文件内的密钥改为你自己的(须在[腾讯云创建密钥并开通OCR服务](https://cloud.tencent.com/document/product/866/34681#null),每月1000免费额度); 46 | 47 | ![](./imgs/3.png) 48 | 49 | **注意等号两侧各有一个空格分隔;** 50 | 51 | 52 | 53 | 3. 启动程序(之后每次开机会自启,无需手动); 54 | 55 | ===========================**自己编译**=========================== 56 | 1. .net framwork 版本为4.7.1,自行下载安装; 57 | 2. clone项目,用vs2019打开sln文件导入项目; 58 | 3. 右键*小小截图*项目,重新生成即可; -------------------------------------------------------------------------------- /imgs/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/imgs/1.png -------------------------------------------------------------------------------- /imgs/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/imgs/2.png -------------------------------------------------------------------------------- /imgs/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/imgs/3.png -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/.signature.p7s -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2007 James Newton-King 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/Newtonsoft.Json.11.0.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/Newtonsoft.Json.11.0.1.nupkg -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/net20/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/net20/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/net35/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/net35/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/net40/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/net40/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/net45/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/net45/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/netstandard1.0/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/netstandard1.0/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/netstandard1.3/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/netstandard1.3/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/netstandard2.0/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/netstandard2.0/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/portable-net40+sl5+win8+wp8+wpa81/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/Newtonsoft.Json.11.0.1/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/Newtonsoft.Json.11.0.1/lib/portable-net45+win8+wp8+wpa81/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.Text.Encodings.Web.4.5.1/.signature.p7s -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) .NET Foundation and Contributors 4 | 5 | All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/System.Text.Encodings.Web.4.5.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.Text.Encodings.Web.4.5.1/System.Text.Encodings.Web.4.5.1.nupkg -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/lib/netstandard1.0/System.Text.Encodings.Web.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.Text.Encodings.Web.4.5.1/lib/netstandard1.0/System.Text.Encodings.Web.dll -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/lib/netstandard2.0/System.Text.Encodings.Web.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.Text.Encodings.Web.4.5.1/lib/netstandard2.0/System.Text.Encodings.Web.dll -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/useSharedDesignerContext.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.Text.Encodings.Web.4.5.1/useSharedDesignerContext.txt -------------------------------------------------------------------------------- /packages/System.Text.Encodings.Web.4.5.1/version.txt: -------------------------------------------------------------------------------- 1 | 627093c87fea3d92b28d0deb53d1259e79b45088 2 | -------------------------------------------------------------------------------- /packages/System.ValueTuple.4.3.0/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.ValueTuple.4.3.0/.signature.p7s -------------------------------------------------------------------------------- /packages/System.ValueTuple.4.3.0/System.ValueTuple.4.3.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.ValueTuple.4.3.0/System.ValueTuple.4.3.0.nupkg -------------------------------------------------------------------------------- /packages/System.ValueTuple.4.3.0/ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | This Microsoft .NET Library may incorporate components from the projects listed 2 | below. Microsoft licenses these components under the Microsoft .NET Library 3 | software license terms. The original copyright notices and the licenses under 4 | which Microsoft received such components are set forth below for informational 5 | purposes only. Microsoft reserves all rights not expressly granted herein, 6 | whether by implication, estoppel or otherwise. 7 | 8 | 1. .NET Core (https://github.com/dotnet/core/) 9 | 10 | .NET Core 11 | Copyright (c) .NET Foundation and Contributors 12 | 13 | The MIT License (MIT) 14 | 15 | Permission is hereby granted, free of charge, to any person obtaining a copy 16 | of this software and associated documentation files (the "Software"), to deal 17 | in the Software without restriction, including without limitation the rights 18 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | copies of the Software, and to permit persons to whom the Software is 20 | furnished to do so, subject to the following conditions: 21 | 22 | The above copyright notice and this permission notice shall be included in all 23 | copies or substantial portions of the Software. 24 | 25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. -------------------------------------------------------------------------------- /packages/System.ValueTuple.4.3.0/lib/netstandard1.0/System.ValueTuple.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.ValueTuple.4.3.0/lib/netstandard1.0/System.ValueTuple.dll -------------------------------------------------------------------------------- /packages/System.ValueTuple.4.3.0/lib/portable-net40+sl4+win8+wp8/System.ValueTuple.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/System.ValueTuple.4.3.0/lib/portable-net40+sl4+win8+wp8/System.ValueTuple.dll -------------------------------------------------------------------------------- /packages/TencentCloudSDK.3.0.308/.signature.p7s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/TencentCloudSDK.3.0.308/.signature.p7s -------------------------------------------------------------------------------- /packages/TencentCloudSDK.3.0.308/TencentCloudSDK.3.0.308.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/TencentCloudSDK.3.0.308/TencentCloudSDK.3.0.308.nupkg -------------------------------------------------------------------------------- /packages/TencentCloudSDK.3.0.308/lib/net45/TencentCloud.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/TencentCloudSDK.3.0.308/lib/net45/TencentCloud.dll -------------------------------------------------------------------------------- /packages/TencentCloudSDK.3.0.308/lib/netstandard2.0/TencentCloud.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THMAIL/xiaoxiao-screenshots-ocr/9633ec9c5e45f18aad993e227bf80c5e353a4d94/packages/TencentCloudSDK.3.0.308/lib/netstandard2.0/TencentCloud.dll -------------------------------------------------------------------------------- /小小截图OCR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31410.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "小小截图OCR", "小小截图OCR\小小截图OCR.csproj", "{5D5AA8CE-7B19-4850-87B8-F442F09C0BA1}" 7 | EndProject 8 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "小小截图", "小小截图\小小截图.vdproj", "{FC20D29E-9C68-4F04-9B00-979EAECD5E5F}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {5D5AA8CE-7B19-4850-87B8-F442F09C0BA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {5D5AA8CE-7B19-4850-87B8-F442F09C0BA1}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {5D5AA8CE-7B19-4850-87B8-F442F09C0BA1}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {5D5AA8CE-7B19-4850-87B8-F442F09C0BA1}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {FC20D29E-9C68-4F04-9B00-979EAECD5E5F}.Debug|Any CPU.ActiveCfg = Debug 21 | {FC20D29E-9C68-4F04-9B00-979EAECD5E5F}.Release|Any CPU.ActiveCfg = Release 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(ExtensibilityGlobals) = postSolution 27 | SolutionGuid = {56CE5A41-4BF7-4C6F-A4FF-9BA7F71413E0} 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /小小截图OCR/AcceptSelectEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Media.Imaging; 8 | 9 | namespace 小小截图OCR { 10 | public class AcceptSelectEventArgs : RoutedEventArgs { 11 | public BitmapSource SelectBitmap { get; } 12 | 13 | public AcceptSelectEventArgs(BitmapSource bitmap, RoutedEvent routedEvent, object source) : base(routedEvent, source) { 14 | SelectBitmap = bitmap; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /小小截图OCR/AcceptSelectHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace 小小截图OCR { 9 | public delegate void AcceptSelectHandler(object sender, AcceptSelectEventArgs e); 10 | } 11 | -------------------------------------------------------------------------------- /小小截图OCR/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 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 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /小小截图OCR/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /小小截图OCR/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 小小截图OCR { 10 | /// 11 | /// App.xaml 的交互逻辑 12 | /// 13 | public partial class App : Application { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /小小截图OCR/Base64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Drawing; 7 | using System.IO; 8 | 9 | namespace 小小截图OCR 10 | { 11 | class Base64 12 | { 13 | //图片转为base64编码的字符串 14 | public string ImgToBase64String(Bitmap imageBitmap) 15 | { 16 | try 17 | { 18 | //Bitmap bmp = new Bitmap(Imagefilename); 19 | Bitmap bmp = imageBitmap; 20 | 21 | MemoryStream ms = new MemoryStream(); 22 | bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 23 | byte[] arr = new byte[ms.Length]; 24 | ms.Position = 0; 25 | ms.Read(arr, 0, (int)ms.Length); 26 | ms.Close(); 27 | return Convert.ToBase64String(arr); 28 | } 29 | catch (Exception ex) 30 | { 31 | return null; 32 | } 33 | } 34 | 35 | //threeebase64编码的字符串转为图片 36 | public Bitmap Base64StringToImage(string strbase64) 37 | { 38 | try 39 | { 40 | byte[] arr = Convert.FromBase64String(strbase64); 41 | MemoryStream ms = new MemoryStream(arr); 42 | Bitmap bmp = new Bitmap(ms); 43 | 44 | bmp.Save(@"d:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 45 | //bmp.Save(@"d:\"test.bmp", ImageFormat.Bmp); 46 | //bmp.Save(@"d:\"test.gif", ImageFormat.Gif); 47 | //bmp.Save(@"d:\"test.png", ImageFormat.Png); 48 | ms.Close(); 49 | return bmp; 50 | } 51 | catch (Exception ex) 52 | { 53 | return null; 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /小小截图OCR/Command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Input; 7 | 8 | namespace 小小截图OCR { 9 | public class Command : ICommand { 10 | public event EventHandler CanExecuteChanged; 11 | 12 | private Action executeAction; 13 | private Func canExecuteAction; 14 | 15 | public Command(Action executeAction, Func canExecuteAction = null) { 16 | this.executeAction = executeAction; 17 | this.canExecuteAction = canExecuteAction; 18 | } 19 | 20 | public bool CanExecute(T parameter) { 21 | return canExecuteAction?.Invoke(parameter) ?? true; 22 | } 23 | 24 | bool ICommand.CanExecute(object parameter) { 25 | if (parameter == null) return true; 26 | return parameter is T param && CanExecute(param); 27 | } 28 | 29 | public void Execute(T parameter) { 30 | executeAction?.Invoke(parameter); 31 | } 32 | 33 | void ICommand.Execute(object parameter) { 34 | Execute((T) parameter); 35 | } 36 | 37 | public void RaiseCanExecuteChanged() { 38 | CanExecuteChanged?.Invoke(this, EventArgs.Empty); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /小小截图OCR/CursorInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace 小小截图OCR { 8 | public struct CursorInfo { 9 | public int Width { get; set; } 10 | public int Height { get; set; } 11 | public int HotX { get; set; } 12 | public int HotY { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /小小截图OCR/HotKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Input; 8 | using System.Windows; 9 | using System.Windows.Interop; 10 | 11 | namespace 小小截图OCR { 12 | [System.Security.SuppressUnmanagedCodeSecurity] 13 | public class HotKey { 14 | /// 15 | /// 热键消息 16 | /// 17 | const int WM_HOTKEY = 0x312; 18 | 19 | /// 20 | /// 注册热键 21 | /// 22 | [DllImport("user32", SetLastError = true)] 23 | static extern bool RegisterHotKey(IntPtr hWnd, int id, ModifierKeys fsModifuers, Keys vk); 24 | 25 | /// 26 | /// 注销热键 27 | /// 28 | [DllImport("user32", SetLastError = true)] 29 | static extern bool UnregisterHotKey(IntPtr hWnd, int id); 30 | 31 | /// 32 | /// 向原子表中添加全局原子 33 | /// 34 | [DllImport("kernel32", SetLastError = true)] 35 | static extern ushort GlobalAddAtom(string lpString); 36 | 37 | /// 38 | /// 在表中搜索全局原子 39 | /// 40 | [DllImport("kernel32", SetLastError = true)] 41 | static extern ushort GlobalFindAtom(string lpString); 42 | 43 | /// 44 | /// 在表中删除全局原子 45 | /// 46 | [DllImport("kernel32", SetLastError = true)] 47 | static extern ushort GlobalDeleteAtom(string nAtom); 48 | 49 | static string GetString(ModifierKeys modifiers, Keys key) 50 | => $"Saar:{modifiers}+{key}"; 51 | 52 | 53 | private HwndSource source; 54 | private Action action; 55 | 56 | public ModifierKeys Modifiers { get; } 57 | public Keys Key { get; } 58 | public int Id { get; } 59 | 60 | private HotKey(Window window, ModifierKeys modifiers, Keys key, Action action) { 61 | Modifiers = modifiers; 62 | Key = key; 63 | this.action = action; 64 | 65 | try { 66 | var helper = new WindowInteropHelper(window); 67 | var hwnd = helper.Handle; 68 | source = HwndSource.FromHwnd(hwnd); 69 | source.AddHook(WndProc); 70 | var strKey = GetString(modifiers, key); 71 | Id = GlobalFindAtom(strKey); 72 | if (Id != 0) { 73 | UnregisterHotKey(hwnd, Id); 74 | } else { 75 | Id = GlobalAddAtom(strKey); 76 | } 77 | 78 | if (!RegisterHotKey(hwnd, Id, modifiers, key)) 79 | throw new Exception(); 80 | } catch (Exception e) { 81 | throw new HotKeyRegisterFailException(e); 82 | } 83 | } 84 | 85 | public static HotKey Register(Window window, ModifierKeys modifiers, Keys key, Action action) { 86 | return new HotKey(window, modifiers, key, action); 87 | } 88 | 89 | public void Unregister() { 90 | UnregisterHotKey(source.Handle, Id); 91 | GlobalDeleteAtom(GetString(Modifiers, Key)); 92 | source.RemoveHook(WndProc); 93 | } 94 | 95 | private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handle) { 96 | if (msg == WM_HOTKEY && (int) wParam == Id) { 97 | action(); 98 | handle = true; 99 | } 100 | return IntPtr.Zero; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /小小截图OCR/HotKeyRegisterFailException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace 小小截图OCR { 8 | public class HotKeyRegisterFailException : Exception { 9 | public HotKeyRegisterFailException(string message, Exception e) : base(message, e) {} 10 | 11 | public HotKeyRegisterFailException(Exception e) : base("注册热键失败。", e) { } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /小小截图OCR/ISelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | 8 | namespace 小小截图OCR { 9 | public interface ISelector { 10 | Action SelectorBeginMove { get; } 11 | Action SelectorMove { get; } 12 | Action SelectorEndMove { get; } 13 | Action SelectorBeginResize { get; } 14 | Action SelectorResize { get; } 15 | Action SelectorEndResize { get; } 16 | 17 | double SelectX { get; set; } 18 | double SelectY { get; set; } 19 | double SelectWidth { get; set; } 20 | double SelectHeight { get; set; } 21 | FrameworkElement Selector { get; } 22 | SelectState SelectState { get; } 23 | bool SelectorCanMove { get; set; } 24 | bool SelectorCanResize { get; set; } 25 | bool SelectorEnabled { get; set; } 26 | 27 | void SetSelectState(SelectState state); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /小小截图OCR/Keys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace 小小截图OCR { 8 | public enum Keys : int { 9 | None = 0, 10 | LButton = 1, 11 | RButton = 2, 12 | Cancel = 3, 13 | MButton = 4, 14 | XButton1 = 5, 15 | XButton2 = 6, 16 | Back = 8, 17 | Tab = 9, 18 | LineFeed = 10, 19 | Clear = 12, 20 | Return = 13, 21 | Enter = 13, 22 | ShiftKey = 16, 23 | ControlKey = 17, 24 | Menu = 18, 25 | Pause = 19, 26 | Capital = 20, 27 | CapsLock = 20, 28 | KanaMode = 21, 29 | HanguelMode = 21, 30 | HangulMode = 21, 31 | JunjaMode = 23, 32 | FinalMode = 24, 33 | HanjaMode = 25, 34 | KanjiMode = 25, 35 | Escape = 27, 36 | IMEConvert = 28, 37 | IMENonconvert = 29, 38 | IMEAccept = 30, 39 | IMEAceept = 30, 40 | IMEModeChange = 31, 41 | Space = 32, 42 | Prior = 33, 43 | PageUp = 33, 44 | Next = 34, 45 | PageDown = 34, 46 | End = 35, 47 | Home = 36, 48 | Left = 37, 49 | Up = 38, 50 | Right = 39, 51 | Down = 40, 52 | Select = 41, 53 | Print = 42, 54 | Execute = 43, 55 | Snapshot = 44, 56 | PrintScreen = 44, 57 | Insert = 45, 58 | Delete = 46, 59 | Help = 47, 60 | D0 = 48, 61 | D1 = 49, 62 | D2 = 50, 63 | D3 = 51, 64 | D4 = 52, 65 | D5 = 53, 66 | D6 = 54, 67 | D7 = 55, 68 | D8 = 56, 69 | D9 = 57, 70 | A = 65, 71 | B = 66, 72 | C = 67, 73 | D = 68, 74 | E = 69, 75 | F = 70, 76 | G = 71, 77 | H = 72, 78 | I = 73, 79 | J = 74, 80 | K = 75, 81 | L = 76, 82 | M = 77, 83 | N = 78, 84 | O = 79, 85 | P = 80, 86 | Q = 81, 87 | R = 82, 88 | S = 83, 89 | T = 84, 90 | U = 85, 91 | V = 86, 92 | W = 87, 93 | X = 88, 94 | Y = 89, 95 | Z = 90, 96 | LWin = 91, 97 | RWin = 92, 98 | Apps = 93, 99 | Sleep = 95, 100 | NumPad0 = 96, 101 | NumPad1 = 97, 102 | NumPad2 = 98, 103 | NumPad3 = 99, 104 | NumPad4 = 100, 105 | NumPad5 = 101, 106 | NumPad6 = 102, 107 | NumPad7 = 103, 108 | NumPad8 = 104, 109 | NumPad9 = 105, 110 | Multiply = 106, 111 | Add = 107, 112 | Separator = 108, 113 | Subtract = 109, 114 | Decimal = 110, 115 | Divide = 111, 116 | F1 = 112, 117 | F2 = 113, 118 | F3 = 114, 119 | F4 = 115, 120 | F5 = 116, 121 | F6 = 117, 122 | F7 = 118, 123 | F8 = 119, 124 | F9 = 120, 125 | F10 = 121, 126 | F11 = 122, 127 | F12 = 123, 128 | F13 = 124, 129 | F14 = 125, 130 | F15 = 126, 131 | F16 = 127, 132 | F17 = 128, 133 | F18 = 129, 134 | F19 = 130, 135 | F20 = 131, 136 | F21 = 132, 137 | F22 = 133, 138 | F23 = 134, 139 | F24 = 135, 140 | NumLock = 144, 141 | Scroll = 145, 142 | LShiftKey = 160, 143 | RShiftKey = 161, 144 | LControlKey = 162, 145 | RControlKey = 163, 146 | LMenu = 164, 147 | RMenu = 165, 148 | BrowserBack = 166, 149 | BrowserForward = 167, 150 | BrowserRefresh = 168, 151 | BrowserStop = 169, 152 | BrowserSearch = 170, 153 | BrowserFavorites = 171, 154 | BrowserHome = 172, 155 | VolumeMute = 173, 156 | VolumeDown = 174, 157 | VolumeUp = 175, 158 | MediaNextTrack = 176, 159 | MediaPreviousTrack = 177, 160 | MediaStop = 178, 161 | MediaPlayPause = 179, 162 | LaunchMail = 180, 163 | SelectMedia = 181, 164 | LaunchApplication1 = 182, 165 | LaunchApplication2 = 183, 166 | OemSemicolon = 186, 167 | Oem1 = 186, 168 | Oemplus = 187, 169 | Oemcomma = 188, 170 | OemMinus = 189, 171 | OemPeriod = 190, 172 | OemQuestion = 191, 173 | Oem2 = 191, 174 | Oemtilde = 192, 175 | Oem3 = 192, 176 | OemOpenBrackets = 219, 177 | Oem4 = 219, 178 | OemPipe = 220, 179 | Oem5 = 220, 180 | OemCloseBrackets = 221, 181 | Oem6 = 221, 182 | OemQuotes = 222, 183 | Oem7 = 222, 184 | Oem8 = 223, 185 | OemBackslash = 226, 186 | Oem102 = 226, 187 | ProcessKey = 229, 188 | Packet = 231, 189 | Attn = 246, 190 | Crsel = 247, 191 | Exsel = 248, 192 | EraseEof = 249, 193 | Play = 250, 194 | Zoom = 251, 195 | NoName = 252, 196 | Pa1 = 253, 197 | OemClear = 254, 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /小小截图OCR/Lisp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Text.RegularExpressions; 7 | using System.Linq.Expressions; 8 | using System.Windows.Data; 9 | using System.Globalization; 10 | using ExpressionBase = System.Linq.Expressions.Expression; 11 | using System.Windows.Markup; 12 | 13 | namespace 小小截图OCR { 14 | [ContentProperty(nameof(Expression))] 15 | [MarkupExtensionReturnType(typeof(object))] 16 | public class Lisp : MarkupExtension, IValueConverter, IMultiValueConverter { 17 | static readonly Regex lexer = new Regex(@"\(|\)|'(?:''|[^'])*'|-?\d+(\.\d*)?|-?\.\d+|\$\d*|[a-z_][a-z\d_]*", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline); 18 | 19 | public delegate dynamic ParamArrayDelegate(params dynamic[] args); 20 | 21 | public static readonly Dictionary RegisterDelegates = new Dictionary() { 22 | ["add"] = (ParamArrayDelegate) (args => { 23 | if (args == null || args.Length == 0) return null; 24 | var sum = args[0]; 25 | for (int i = 1; i < args.Length; i++) sum += args[i]; 26 | return sum; 27 | }), 28 | ["sub"] = (Func) ((x, y) => x - y), 29 | ["mul"] = (Func) ((x, y) => x * y), 30 | ["div"] = (Func) ((x, y) => x / y), 31 | ["true"] = (Func) (() => true), 32 | ["false"] = (Func) (() => false), 33 | ["if"] = (Func) ((cond, T, F) => cond ? T : F), 34 | ["lt"] = (Func) ((x, y) => x < y), 35 | ["gt"] = (Func) ((x, y) => x > y), 36 | ["le"] = (Func) ((x, y) => x <= y), 37 | ["ge"] = (Func) ((x, y) => x >= y), 38 | ["eq"] = (Func) ((x, y) => x == y), 39 | ["ne"] = (Func) ((x, y) => x != y), 40 | ["and"] = (Func) ((x, y) => x && y), 41 | ["or"] = (Func) ((x, y) => x || y), 42 | ["not"] = (Func) (x => !x), 43 | ["concat"] = (ParamArrayDelegate) (args => string.Concat(args)), 44 | ["join"] = (ParamArrayDelegate) (args => string.Join((string) args[0], new ArraySegment(args, 1, args.Length - 1))), 45 | ["int"] = (Func) (x => Math.Floor((double) x)), 46 | ["max"] = (Func) ((x, y) => Math.Max(x, y)), 47 | ["min"] = (Func) ((x, y) => Math.Min(x, y)), 48 | ["in"] = (Func) ((x, y) => Array.IndexOf(y, x) >= 0), 49 | ["format"] = (ParamArrayDelegate) (args => string.Format((string) args[0], new ArraySegment(args, 1, args.Length - 1).ToArray())) 50 | }; 51 | 52 | static ExpressionBase CreateInvokeExpression(string funcName, IReadOnlyCollection args) { 53 | var lambda = RegisterDelegates[funcName]; 54 | var argTypes = lambda.GetType().GetMethod("Invoke").GetParameters(); 55 | if (argTypes.Length == 0 || argTypes[0].GetCustomAttributes(typeof(ParamArrayAttribute), true).Length == 0) { 56 | if (lambda.Method.GetParameters().Length != args.Count) { 57 | throw new InvalidOperationException($"函数{funcName}的参数数量不匹配。"); 58 | } 59 | } else { 60 | args = new[] { ExpressionBase.NewArrayInit(typeof(object), args) }; 61 | } 62 | var lambdaExpr = ExpressionBase.Constant(lambda); 63 | return ExpressionBase.Invoke(lambdaExpr, args); 64 | } 65 | 66 | static string NextToken(string expr, ref int index) { 67 | var m = lexer.Match(expr, index); 68 | if (m.Success) { 69 | index = m.Index + m.Length; 70 | return m.Value; 71 | } 72 | return null; 73 | } 74 | 75 | static ExpressionBase LispParse(string expr, ref int index, IDictionary argsMap) { 76 | var token = NextToken(expr, ref index); 77 | if (token == "(") { 78 | var funcName = NextToken(expr, ref index); 79 | var args = new List(); 80 | while (LispParse(expr, ref index, argsMap) is ExpressionBase arg) args.Add(arg); 81 | 82 | return CreateInvokeExpression(funcName, args); 83 | } else if (token != null && token != ")") { 84 | if (token[0] == '\'') { 85 | return ExpressionBase.Constant(token.Substring(1, token.Length - 2).Replace("''", "'")); 86 | } else if (char.IsDigit(token[0]) || token[0] == '-' || token[0] == '.') { 87 | return ExpressionBase.Constant(double.Parse(token), typeof(object)); 88 | } else { 89 | int argId = token != "$" ? int.Parse(token.Substring(1)) : int.MaxValue; 90 | if (!argsMap.TryGetValue(argId, out var param)) { 91 | argsMap[argId] = param = ExpressionBase.Parameter(typeof(object), token); 92 | } 93 | return param; 94 | } 95 | } 96 | return null; 97 | } 98 | 99 | public static Delegate Compile(string lispExpr) { 100 | int index = 0; 101 | var argsMap = new SortedDictionary(); 102 | var invoke = LispParse(lispExpr, ref index, argsMap); 103 | var lambda = ExpressionBase.Lambda(invoke, argsMap.Values); 104 | if (lambda.CanReduce) lambda = lambda.Reduce() as LambdaExpression; 105 | return lambda.Compile(); 106 | } 107 | 108 | 109 | public class LispException : System.Exception { 110 | public LispException() { } 111 | public LispException(string message) : base(message) { } 112 | } 113 | 114 | 115 | private string expression; 116 | private Delegate @delegate; 117 | 118 | 119 | public Lisp() { } 120 | public Lisp(string expression) => Expression = expression; 121 | 122 | public string Expression { 123 | get => expression; 124 | set { 125 | if (expression != value) { 126 | expression = value; 127 | if (!string.IsNullOrWhiteSpace(value)) { 128 | @delegate = Compile(value); 129 | } else { 130 | @delegate = null; 131 | } 132 | } 133 | } 134 | } 135 | 136 | public Delegate Delegate => @delegate; 137 | 138 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) { 139 | if (@delegate == null) throw new LispException($"{nameof(Expression)}无效。"); 140 | return parameter != null 141 | ? @delegate.DynamicInvoke(value, parameter) 142 | : @delegate.DynamicInvoke(value); 143 | } 144 | 145 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 146 | throw new NotImplementedException(); 147 | } 148 | 149 | object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { 150 | if (@delegate == null) throw new LispException($"{nameof(Expression)}无效。"); 151 | if (parameter != null) { 152 | var newValues = new object[values.Length + 1]; 153 | values.CopyTo(newValues, 0); 154 | newValues[values.Length] = parameter; 155 | return @delegate.DynamicInvoke(newValues); 156 | } 157 | return @delegate.DynamicInvoke(values); 158 | } 159 | 160 | object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { 161 | throw new NotImplementedException(); 162 | } 163 | 164 | public override object ProvideValue(IServiceProvider serviceProvider) { 165 | return this; 166 | } 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /小小截图OCR/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /小小截图OCR/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using System.Windows.Data; 10 | using System.Windows.Documents; 11 | using System.Windows.Input; 12 | using System.Windows.Media; 13 | using System.Windows.Media.Imaging; 14 | using System.Windows.Navigation; 15 | using System.Windows.Shapes; 16 | using System.Diagnostics; 17 | using System.Windows.Interop; 18 | using System.Drawing; 19 | using System.Drawing.Imaging; 20 | using System.IO; 21 | using System.Text.RegularExpressions; 22 | 23 | namespace 小小截图OCR 24 | { 25 | /// 26 | /// MainWindow.xaml 的交互逻辑 27 | /// 28 | public partial class MainWindow : Window 29 | { 30 | public ICommand HideCommand { get; } = new Command(win => win.Visibility = Visibility.Hidden); 31 | 32 | private IReadOnlyList windowRects; 33 | 34 | private Base64 base64 = new Base64(); 35 | private OcrTools ocrTools = new OcrTools(); 36 | 37 | public MainWindow() 38 | { 39 | InitializeComponent(); 40 | 41 | pixelObserver.DataContext = editor; 42 | tipSize.DataContext = editor; 43 | tipRGB.DataContext = pixelObserver; 44 | 45 | startup(); 46 | } 47 | 48 | private void Grid_PreviewMouseMove(object sender, MouseEventArgs e) 49 | { 50 | var point = e.GetPosition(editor); 51 | pixelObserver.X = point.X; 52 | pixelObserver.Y = point.Y; 53 | } 54 | 55 | private void FocusWindow() 56 | { 57 | var curr = Mouse.GetPosition(this); 58 | foreach (var r in windowRects) 59 | { 60 | if (r.Contains(curr)) 61 | { 62 | editor.SelectX = r.X; 63 | editor.SelectY = r.Y; 64 | editor.SelectWidth = r.Width; 65 | editor.SelectHeight = r.Height; 66 | break; 67 | } 68 | } 69 | } 70 | 71 | private void editor_MouseMove(object sender, MouseEventArgs e) 72 | { 73 | if (editor.SelectState == SelectState.Fixed) 74 | { 75 | FocusWindow(); 76 | } 77 | } 78 | 79 | private void editor_Click(object sender, RoutedEventArgs e) 80 | { 81 | Debug.Print("click"); 82 | if (editor.SelectState == SelectState.Fixed) editor.Select(); 83 | } 84 | 85 | private void editor_AcceptSelect(object sender, AcceptSelectEventArgs e) 86 | { 87 | var curr = Mouse.GetPosition(this); 88 | if (curr.X < editor.SelectX + editor.SelectWidth / 2) 89 | { 90 | if(curr.Y < editor.SelectY + editor.SelectHeight / 2) 91 | { 92 | Console.WriteLine("复制截图"); 93 | Clipboard.SetImage(e.SelectBitmap); 94 | } 95 | else 96 | { 97 | Console.WriteLine("保存到桌面"); 98 | Bitmap tempImgBitmap = GetBitmap(e.SelectBitmap); 99 | 100 | string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 101 | 102 | 103 | var picFiles = Directory.GetFiles(desktopPath, "小小截图*.jpg"); 104 | int maxNum = 0; 105 | foreach (var fileName in picFiles) 106 | { 107 | Console.WriteLine(fileName); 108 | 109 | string pattern = @"小小截图(?\d+?).jpg"; 110 | Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); 111 | Match match = regex.Match(fileName); 112 | if (match.Success) 113 | { 114 | int picNum = int.Parse(match.Groups["num"].Value); 115 | Console.WriteLine(picNum); 116 | 117 | if(picNum > maxNum) 118 | { 119 | maxNum = picNum; 120 | } 121 | } 122 | } 123 | 124 | tempImgBitmap.Save(desktopPath + String.Format("\\小小截图{0}.jpg", maxNum+1)); 125 | } 126 | } 127 | else 128 | { 129 | if (curr.Y < editor.SelectY + editor.SelectHeight / 2) 130 | { 131 | Console.WriteLine("通用识别"); 132 | Bitmap tempImgBitmap = GetBitmap(e.SelectBitmap); 133 | string tempImgBase64 = base64.ImgToBase64String(tempImgBitmap); 134 | ocrTools.GeneralBasicOCR(tempImgBase64); 135 | } 136 | else 137 | { 138 | Console.WriteLine("手写体识别"); 139 | Bitmap tempImgBitmap = GetBitmap(e.SelectBitmap); 140 | string tempImgBase64 = base64.ImgToBase64String(tempImgBitmap); 141 | ocrTools.GeneralHandwritingOCR(tempImgBase64); 142 | } 143 | } 144 | Hide(); 145 | } 146 | 147 | Bitmap GetBitmap(BitmapSource source) 148 | { 149 | Bitmap bmp = new Bitmap( 150 | source.PixelWidth, 151 | source.PixelHeight, 152 | System.Drawing.Imaging.PixelFormat.Format32bppPArgb); 153 | BitmapData data = bmp.LockBits( 154 | new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), 155 | ImageLockMode.WriteOnly, 156 | System.Drawing.Imaging.PixelFormat.Format32bppPArgb); 157 | source.CopyPixels( 158 | Int32Rect.Empty, 159 | data.Scan0, 160 | data.Height * data.Stride, 161 | data.Stride); 162 | bmp.UnlockBits(data); 163 | return bmp; 164 | } 165 | 166 | private void Window_Loaded(object sender, RoutedEventArgs e) 167 | { 168 | const int WS_EX_TOOLWINDOW = 0x00000080; 169 | var helper = new WindowInteropHelper(this); 170 | var exStyle = Tool.GetWindowExStyle(helper.Handle); 171 | Tool.SetWindowExStyle(helper.Handle, exStyle | WS_EX_TOOLWINDOW); 172 | 173 | HotKey.Register(this, ModifierKeys.Alt, Keys.A, delegate 174 | { 175 | if (Visibility != Visibility.Visible) 176 | { 177 | editor.BackgroundBitmap = Tool.ScreenSnapshot; 178 | editor.Reset(); 179 | windowRects = Tool.GetWindowRects(); 180 | Show(); 181 | } 182 | }); 183 | Hide(); 184 | } 185 | 186 | private void editor_Close(object sender, RoutedEventArgs e) 187 | { 188 | Hide(); 189 | } 190 | 191 | private void editor_CancelSelect(object sender, RoutedEventArgs e) 192 | { 193 | editor.Reset(); 194 | FocusWindow(); 195 | } 196 | 197 | /// 198 | /// 将文件放到启动文件夹中开机启动 199 | /// 200 | /// 启动程序 201 | /// 快捷方式名称 202 | /// 描述 203 | private bool startup() 204 | { 205 | string directory = Environment.GetFolderPath(Environment.SpecialFolder.Startup); 206 | string targetPath = Process.GetCurrentProcess().MainModule.FileName; 207 | Console.WriteLine(directory); 208 | Console.WriteLine(targetPath); 209 | string shortcutName = "小小截图"; 210 | 211 | try 212 | { 213 | if (!Directory.Exists(directory)) 214 | { 215 | Directory.CreateDirectory(directory); 216 | } 217 | 218 | //添加引用 Com 中搜索 Windows Script Host Object Model 219 | string shortcutPath = System.IO.Path.Combine(directory, string.Format("{0}.lnk", shortcutName)); 220 | 221 | if (File.Exists(shortcutPath)) 222 | { 223 | return true; 224 | } 225 | 226 | IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); 227 | IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);//创建快捷方式对象 228 | shortcut.TargetPath = targetPath;//指定目标路径 229 | shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(targetPath);//设置起始位置 230 | //shortcut.WindowStyle = 1;//设置运行方式,默认为常规窗口 231 | //shortcut.Description = description;//设置备注 232 | shortcut.IconLocation = targetPath; //设置图标路径 233 | shortcut.Save();//保存快捷方式 234 | 235 | return true; 236 | } 237 | catch 238 | { } 239 | return false; 240 | } 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /小小截图OCR/OcrTools.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using System.Windows; 6 | using Newtonsoft.Json; 7 | using Newtonsoft.Json.Linq; 8 | using TencentCloud.Common; 9 | using TencentCloud.Common.Profile; 10 | using TencentCloud.Ocr.V20181119; 11 | using TencentCloud.Ocr.V20181119.Models; 12 | 13 | namespace 小小截图OCR 14 | { 15 | class OcrTools 16 | { 17 | 18 | private string secretId = ""; 19 | private string secretKey = ""; 20 | 21 | public OcrTools() 22 | { 23 | try 24 | { 25 | // 创建一个 StreamReader 的实例来读取文件 26 | // using 语句也能关闭 StreamReader 27 | using (StreamReader sr = new StreamReader("./config.ini")) 28 | { 29 | string line; 30 | // 从文件读取并显示行,直到文件的末尾 31 | while ((line = sr.ReadLine()) != null) 32 | { 33 | Console.WriteLine(line); 34 | string[] separatingStrings = { " = " }; 35 | string[] configArray = line.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries); 36 | 37 | /*foreach(var word in configArray) 38 | { 39 | Console.WriteLine(word); 40 | }*/ 41 | 42 | if (configArray[0] == "SecretId") 43 | { 44 | secretId = configArray[1]; 45 | } 46 | else if (configArray[0] == "SecretKey") 47 | { 48 | secretKey = configArray[1]; 49 | } 50 | else 51 | { 52 | Console.WriteLine("配置文件格式错误"); 53 | System.Environment.Exit(1); 54 | } 55 | } 56 | Console.WriteLine((secretId, secretKey)); 57 | } 58 | } 59 | catch (Exception e) 60 | { 61 | Console.WriteLine("配置文件读取失败"); 62 | Console.WriteLine(e.Message); 63 | System.Environment.Exit(1); 64 | } 65 | } 66 | 67 | public void GeneralBasicOCR(string imageBase64) 68 | { 69 | try 70 | { 71 | Credential cred = new Credential 72 | { 73 | SecretId = secretId, 74 | SecretKey = secretKey 75 | }; 76 | 77 | ClientProfile clientProfile = new ClientProfile(); 78 | HttpProfile httpProfile = new HttpProfile(); 79 | httpProfile.Endpoint = ("ocr.tencentcloudapi.com"); 80 | clientProfile.HttpProfile = httpProfile; 81 | 82 | OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile); 83 | GeneralBasicOCRRequest req = new GeneralBasicOCRRequest(); 84 | //req.ImageBase64 = base64.ImgToBase64String("C:\\Users\\lei\\Pictures\\Saved Pictures\\1 (107).jpg"); 85 | req.ImageBase64 = imageBase64; 86 | Console.WriteLine(req.ImageBase64); 87 | GeneralBasicOCRResponse resp = client.GeneralBasicOCRSync(req); 88 | string result = AbstractModel.ToJsonString(resp); 89 | Console.WriteLine(result); 90 | 91 | resParse(result); 92 | 93 | } 94 | catch (Exception e) 95 | { 96 | Console.WriteLine(e.ToString()); 97 | } 98 | } 99 | 100 | public void GeneralHandwritingOCR(string imageBase64) 101 | { 102 | try 103 | { 104 | Credential cred = new Credential 105 | { 106 | SecretId = secretId, 107 | SecretKey = secretKey 108 | }; 109 | 110 | ClientProfile clientProfile = new ClientProfile(); 111 | HttpProfile httpProfile = new HttpProfile(); 112 | httpProfile.Endpoint = ("ocr.tencentcloudapi.com"); 113 | clientProfile.HttpProfile = httpProfile; 114 | 115 | OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile); 116 | GeneralHandwritingOCRRequest req = new GeneralHandwritingOCRRequest(); 117 | req.ImageBase64 = imageBase64; 118 | GeneralHandwritingOCRResponse resp = client.GeneralHandwritingOCRSync(req); 119 | 120 | string result = AbstractModel.ToJsonString(resp); 121 | Console.WriteLine(result); 122 | 123 | resParse(result); 124 | } 125 | catch (Exception e) 126 | { 127 | Console.WriteLine(e.ToString()); 128 | } 129 | } 130 | 131 | private void resParse(string result) 132 | { 133 | //解析json 134 | dynamic resultJson = JsonConvert.DeserializeObject(result); 135 | dynamic resultTextArray = resultJson.TextDetections; 136 | 137 | string finalResult = ""; 138 | int latestMinY = 0, latestMaxY = 0; 139 | foreach (var resultText in resultTextArray) 140 | { 141 | /*//Console.WriteLine(resultText.DetectedText); 142 | string parag = (string)resultText.AdvancedInfo; 143 | //Console.WriteLine(parag.Substring(20,1)); 144 | 145 | if (parag.Substring(20, 1) == "1" && finalResult != "") 146 | { 147 | finalResult += "\r"; 148 | } 149 | else if (parag.Substring(20, 1) != "1" && finalResult != "") 150 | { 151 | finalResult += " "; 152 | }*/ 153 | 154 | int currMinY = 999999999;//设置一个极大值 155 | int currMaxY = 0; 156 | foreach (var XY in resultText.Polygon) 157 | { 158 | if (XY.Y < currMinY) 159 | { 160 | currMinY = XY.Y; 161 | } 162 | 163 | if (XY.Y > currMaxY) 164 | { 165 | currMaxY = XY.Y; 166 | } 167 | } 168 | Console.WriteLine((currMinY, currMaxY)); 169 | //检测与上一个parag是否处于一行,置信度设为90 170 | //if(currMinY >= latestMinY && currMinY < latestMaxY)//有处于一行的可能 171 | if (!(currMaxY < latestMinY || currMinY > latestMaxY))//有处于一行的可能 172 | { 173 | //计算重合度 174 | double coincidenceDegree = (double)(latestMaxY - currMinY) / (double)(currMaxY - latestMinY); 175 | Console.WriteLine(("置信度为:", coincidenceDegree, resultText.DetectedText)); 176 | if (coincidenceDegree < 0.8) 177 | { 178 | //不处于同一行,换行 179 | if (finalResult != "") 180 | { 181 | finalResult += "\r" + resultText.DetectedText; 182 | } 183 | else 184 | { 185 | finalResult += resultText.DetectedText; 186 | } 187 | } 188 | else//处于同一行 189 | { 190 | finalResult += " " + resultText.DetectedText; 191 | } 192 | } 193 | else//不处于同一行,换行 194 | { 195 | if (finalResult != "") 196 | { 197 | finalResult += "\r" + resultText.DetectedText; 198 | } 199 | else 200 | { 201 | finalResult += resultText.DetectedText; 202 | } 203 | } 204 | 205 | //保存该行坐标信息 206 | latestMinY = currMinY; 207 | latestMaxY = currMaxY; 208 | 209 | } 210 | 211 | 212 | //Clipboard.SetText(finalResult); 213 | string tempPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 214 | string tempFilePath = tempPath + "\\temp.txt"; 215 | using (StreamWriter sw = new StreamWriter(tempFilePath)) 216 | { 217 | sw.Write(finalResult); 218 | } 219 | System.Diagnostics.Process.Start("notepad.exe", tempFilePath); 220 | 221 | //Thread.Sleep(300); 222 | 223 | // File.Delete(tempFilePath); 224 | } 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /小小截图OCR/PixelObserver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace 小小截图OCR { 17 | public class PixelObserver : Control { 18 | static PixelObserver() { 19 | DefaultStyleKeyProperty.OverrideMetadata(typeof(PixelObserver), new FrameworkPropertyMetadata(typeof(PixelObserver))); 20 | } 21 | 22 | 23 | public double X { 24 | get { return (double) GetValue(XProperty); } 25 | set { SetValue(XProperty, value); } 26 | } 27 | 28 | public static readonly DependencyProperty XProperty = 29 | DependencyProperty.Register("X", typeof(double), typeof(PixelObserver), new PropertyMetadata(0d, NoticeRender)); 30 | 31 | public double Y { 32 | get { return (double) GetValue(YProperty); } 33 | set { SetValue(YProperty, value); } 34 | } 35 | 36 | public static readonly DependencyProperty YProperty = 37 | DependencyProperty.Register("Y", typeof(double), typeof(PixelObserver), new PropertyMetadata(0d, NoticeRender)); 38 | 39 | public double ScaleX { 40 | get { return (double) GetValue(ScaleXProperty); } 41 | set { SetValue(ScaleXProperty, value); } 42 | } 43 | 44 | public static readonly DependencyProperty ScaleXProperty = 45 | DependencyProperty.Register("ScaleX", typeof(double), typeof(PixelObserver), new PropertyMetadata(5d, NoticeRender)); 46 | 47 | public double ScaleY { 48 | get { return (double) GetValue(ScaleYProperty); } 49 | set { SetValue(ScaleYProperty, value); } 50 | } 51 | 52 | public static readonly DependencyProperty ScaleYProperty = 53 | DependencyProperty.Register("ScaleY", typeof(double), typeof(PixelObserver), new PropertyMetadata(5d, NoticeRender)); 54 | 55 | public BitmapSource BitmapSource { 56 | get { return (BitmapSource) GetValue(BitmapSourceProperty); } 57 | set { SetValue(BitmapSourceProperty, value); } 58 | } 59 | 60 | public static readonly DependencyProperty BitmapSourceProperty = 61 | DependencyProperty.Register("BitmapSource", typeof(BitmapSource), typeof(PixelObserver), new PropertyMetadata(null, NoticeRender)); 62 | 63 | public Brush SelectorBrush { 64 | get { return (Brush) GetValue(SelectorBrushProperty); } 65 | set { SetValue(SelectorBrushProperty, value); } 66 | } 67 | 68 | public static readonly DependencyProperty SelectorBrushProperty = 69 | DependencyProperty.Register("SelectorBrush", typeof(Brush), typeof(PixelObserver), new PropertyMetadata(new SolidColorBrush(Color.FromArgb(192, 255, 128, 128)), NoticeRender)); 70 | 71 | public Color SelectColor { 72 | get { return (Color) GetValue(SelectColorProperty); } 73 | protected set { SetValue(SelectColorPropertyKey, value); } 74 | } 75 | 76 | private static readonly DependencyPropertyKey SelectColorPropertyKey = 77 | DependencyProperty.RegisterReadOnly("SelectColor", typeof(Color), typeof(PixelObserver), new PropertyMetadata()); 78 | 79 | public static readonly DependencyProperty SelectColorProperty = SelectColorPropertyKey.DependencyProperty; 80 | 81 | private static void NoticeRender(DependencyObject d, DependencyPropertyChangedEventArgs e) { 82 | var @this = d as PixelObserver; 83 | @this.InvalidateVisual(); 84 | 85 | if (e.Property == XProperty || e.Property == YProperty || e.Property == BitmapSourceProperty) { 86 | var bitmap = @this.BitmapSource; 87 | int x = (int) @this.X, y = (int) @this.Y; 88 | bool invaild = bitmap == null || x < 0 || y < 0 || x >= bitmap.PixelWidth || y >= bitmap.PixelHeight; 89 | 90 | if (!invaild) { 91 | var pixel = new int[1]; 92 | bitmap.CopyPixels(new Int32Rect(x, y, 1, 1), pixel, 4, 0); 93 | var b = (byte) (pixel[0] & 0xff); 94 | var g = (byte) ((pixel[0] >> 8) & 0xff); 95 | var r = (byte) ((pixel[0] >> 16) & 0xff); 96 | @this.SetValue(SelectColorPropertyKey, Color.FromRgb(r, g, b)); 97 | } else { 98 | @this.ClearValue(SelectColorPropertyKey); 99 | } 100 | } 101 | } 102 | 103 | unsafe private Color[,] GetPixels(BitmapSource bitmap, int centerX, int centerY, int rangeX, int rangeY) { 104 | int width = rangeX * 2 + 1, height = rangeY * 2 + 1; 105 | var rect = new Rect(centerX - rangeX, centerY - rangeY, width, height); 106 | var imageRect = new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight); 107 | imageRect.Intersect(rect); 108 | var sourceRect = new Int32Rect((int) imageRect.X, (int) imageRect.Y, (int) imageRect.Width, (int) imageRect.Height); 109 | var pixels = new int[sourceRect.Width * sourceRect.Height]; 110 | bitmap.CopyPixels(sourceRect, pixels, sourceRect.Width * 4, 0); 111 | 112 | int offsetX = rect.X < 0 ? -(int) rect.X : 0; 113 | int offsetY = rect.Y < 0 ? -(int) rect.Y : 0; 114 | var result = new Color[width, height]; 115 | for (int y = 0; y < sourceRect.Height; y++) { 116 | for (int x = 0; x < sourceRect.Width; x++) { 117 | var p = pixels[y * sourceRect.Width + x]; 118 | var b = (byte) (p & 0xff); 119 | var g = (byte) ((p >> 8) & 0xff); 120 | var r = (byte) ((p >> 16) & 0xff); 121 | result[x + offsetX, y + offsetY] = Color.FromRgb(r, g, b); 122 | } 123 | } 124 | return result; 125 | } 126 | 127 | protected override void OnRender(DrawingContext dc) { 128 | base.OnRender(dc); 129 | 130 | var bitmap = BitmapSource; 131 | if (bitmap == null) return; 132 | 133 | var width = ActualWidth; 134 | var height = ActualHeight; 135 | var scaleX = ScaleX; 136 | var scaleY = ScaleY; 137 | int rangeX = (int) Math.Ceiling((width - scaleX) / 2 / scaleX); 138 | int rangeY = (int) Math.Ceiling((height - scaleY) / 2 / scaleY); 139 | 140 | var pixels = GetPixels(bitmap, (int) X, (int) Y, rangeX, rangeY); 141 | var offsetX = ((width - scaleX) / 2 / scaleX - rangeX) * scaleX; 142 | var offsetY = ((height - scaleY) / 2 / scaleY - rangeY) * scaleY; 143 | var pixelWidth = pixels.GetLength(0); 144 | var pixelHeight = pixels.GetLength(1); 145 | var selectorBrush = SelectorBrush.Clone(); 146 | 147 | selectorBrush.Freeze(); 148 | 149 | for (int y = 0; y < pixelHeight; y++) { 150 | for (int x = 0; x < pixelWidth; x++) { 151 | var rect = new Rect(offsetX + x * scaleX, offsetY + y * scaleY, scaleX, scaleY); 152 | var brush = new SolidColorBrush(pixels[x, y]); 153 | brush.Freeze(); 154 | dc.DrawRectangle(brush, null, rect); 155 | 156 | if ((x == rangeX && y != rangeY) || (x != rangeX && y == rangeY)) { 157 | dc.DrawRectangle(selectorBrush, null, rect); 158 | } 159 | } 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /小小截图OCR/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("小小截图OCR")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("小小截图OCR")] 15 | [assembly: AssemblyCopyright("Copyright © 2021")] 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 | -------------------------------------------------------------------------------- /小小截图OCR/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace 小小截图OCR.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", "16.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal 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 | internal 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("小小截图OCR.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /小小截图OCR/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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /小小截图OCR/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace 小小截图OCR.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /小小截图OCR/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /小小截图OCR/SelectState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace 小小截图OCR { 8 | public enum SelectState { 9 | Fixed, Move, Resize, Selected 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /小小截图OCR/TestWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 19 | 20 | 21 | 22 | 30 | 31 | 32 | 33 | 36 |