├── .gitattributes ├── .gitignore ├── LICENSE ├── PythonImageViewer.sln ├── PythonImageViewer ├── Mandrill.bmp ├── PythonImageViewer.pyproj └── imageviewer.py └── 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 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2022 Akira 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /PythonImageViewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PythonImageViewer", "PythonImageViewer\PythonImageViewer.pyproj", "{FFBA771A-72A0-4F2B-82B4-4FB05D32D762}" 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 | {FFBA771A-72A0-4F2B-82B4-4FB05D32D762}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {FFBA771A-72A0-4F2B-82B4-4FB05D32D762}.Release|Any CPU.ActiveCfg = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(ExtensibilityGlobals) = postSolution 21 | SolutionGuid = {7FA36059-7D96-4EDC-B112-49DD538CA8BE} 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /PythonImageViewer/Mandrill.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImagingSolution/PythonImageViewer/db74b4f27a12872ff4549fb111b2ec87be138b68/PythonImageViewer/Mandrill.bmp -------------------------------------------------------------------------------- /PythonImageViewer/PythonImageViewer.pyproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Debug 4 | 2.0 5 | ffba771a-72a0-4f2b-82b4-4fb05d32d762 6 | . 7 | imageviewer.py 8 | 9 | 10 | . 11 | . 12 | PythonImageViewer 13 | PythonImageViewer 14 | 15 | 16 | true 17 | false 18 | 19 | 20 | true 21 | false 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /PythonImageViewer/imageviewer.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk # ウィンドウ作成用 2 | from tkinter import filedialog # ファイルを開くダイアログ用 3 | from PIL import Image, ImageTk # 画像データ用 4 | import math # 回転の計算用 5 | import numpy as np # アフィン変換行列演算用 6 | import os # ディレクトリ操作用 7 | 8 | class Application(tk.Frame): 9 | def __init__(self, master=None): 10 | super().__init__(master) 11 | 12 | self.master.geometry("600x400") 13 | 14 | self.pil_image = None # 表示する画像データ 15 | self.my_title = "Python Image Viewer" 16 | 17 | # ウィンドウの設定 18 | self.master.title(self.my_title) 19 | 20 | # 実行内容 21 | self.create_menu() # メニューの作成 22 | self.create_widget() # ウィジェットの作成 23 | 24 | # 初期アフィン変換行列 25 | self.reset_transform() 26 | 27 | def menu_open_clicked(self, event=None): 28 | # ファイル→開く 29 | filename = tk.filedialog.askopenfilename( 30 | filetypes = [("Image file", ".bmp .png .jpg .tif"), ("Bitmap", ".bmp"), ("PNG", ".png"), ("JPEG", ".jpg"), ("Tiff", ".tif") ], # ファイルフィルタ 31 | initialdir = os.getcwd() # カレントディレクトリ 32 | ) 33 | 34 | # 画像ファイルを設定する 35 | self.set_image(filename) 36 | 37 | def menu_quit_clicked(self): 38 | # ウィンドウを閉じる 39 | self.master.destroy() 40 | 41 | # create_menuメソッドを定義 42 | def create_menu(self): 43 | self.menu_bar = tk.Menu(self) # Menuクラスからmenu_barインスタンスを生成 44 | 45 | self.file_menu = tk.Menu(self.menu_bar, tearoff = tk.OFF) 46 | self.menu_bar.add_cascade(label="File", menu=self.file_menu) 47 | 48 | self.file_menu.add_command(label="Open", command = self.menu_open_clicked, accelerator="Ctrl+O") 49 | self.file_menu.add_separator() # セパレーターを追加 50 | self.file_menu.add_command(label="Exit", command = self.menu_quit_clicked) 51 | 52 | self.menu_bar.bind_all("", self.menu_open_clicked) # ファイルを開くのショートカット(Ctrol-Oボタン) 53 | 54 | self.master.config(menu=self.menu_bar) # メニューバーの配置 55 | 56 | # create_widgetメソッドを定義 57 | def create_widget(self): 58 | 59 | # ステータスバー相当(親に追加) 60 | frame_statusbar = tk.Frame(self.master, bd=1, relief = tk.SUNKEN) 61 | self.label_image_info = tk.Label(frame_statusbar, text="image info", anchor=tk.E, padx = 5) 62 | self.label_image_pixel = tk.Label(frame_statusbar, text="(x, y)", anchor=tk.W, padx = 5) 63 | self.label_image_info.pack(side=tk.RIGHT) 64 | self.label_image_pixel.pack(side=tk.LEFT) 65 | frame_statusbar.pack(side=tk.BOTTOM, fill=tk.X) 66 | 67 | # Canvas 68 | self.canvas = tk.Canvas(self.master, background="black") 69 | self.canvas.pack(expand=True, fill=tk.BOTH) # この両方でDock.Fillと同じ 70 | 71 | # マウスイベント 72 | self.master.bind("", self.mouse_down_left) # MouseDown 73 | self.master.bind("", self.mouse_move_left) # MouseDrag(ボタンを押しながら移動) 74 | self.master.bind("", self.mouse_move) # MouseMove 75 | self.master.bind("", self.mouse_double_click_left) # MouseDoubleClick 76 | self.master.bind("", self.mouse_wheel) # MouseWheel 77 | 78 | def set_image(self, filename): 79 | ''' 画像ファイルを開く ''' 80 | if not filename: 81 | return 82 | # PIL.Imageで開く 83 | self.pil_image = Image.open(filename) 84 | # 画像全体に表示するようにアフィン変換行列を設定 85 | self.zoom_fit(self.pil_image.width, self.pil_image.height) 86 | # 画像の表示 87 | self.draw_image(self.pil_image) 88 | 89 | # ウィンドウタイトルのファイル名を設定 90 | self.master.title(self.my_title + " - " + os.path.basename(filename)) 91 | # ステータスバーに画像情報を表示する 92 | self.label_image_info["text"] = f"{self.pil_image.format} : {self.pil_image.width} x {self.pil_image.height} {self.pil_image.mode}" 93 | # カレントディレクトリの設定 94 | os.chdir(os.path.dirname(filename)) 95 | 96 | # ------------------------------------------------------------------------------- 97 | # マウスイベント 98 | # ------------------------------------------------------------------------------- 99 | def mouse_down_left(self, event): 100 | ''' マウスの左ボタンを押した ''' 101 | self.__old_event = event 102 | 103 | def mouse_move_left(self, event): 104 | ''' マウスの左ボタンをドラッグ ''' 105 | if (self.pil_image == None): 106 | return 107 | self.translate(event.x - self.__old_event.x, event.y - self.__old_event.y) 108 | self.redraw_image() # 再描画 109 | self.__old_event = event 110 | 111 | def mouse_move(self, event): 112 | ''' マウスの左ボタンをドラッグ ''' 113 | if (self.pil_image == None): 114 | return 115 | 116 | image_point = self.to_image_point(event.x, event.y) 117 | if image_point != []: 118 | self.label_image_pixel["text"] = (f"({image_point[0]:.2f}, {image_point[1]:.2f})") 119 | else: 120 | self.label_image_pixel["text"] = ("(--, --)") 121 | 122 | 123 | def mouse_double_click_left(self, event): 124 | ''' マウスの左ボタンをダブルクリック ''' 125 | if self.pil_image == None: 126 | return 127 | self.zoom_fit(self.pil_image.width, self.pil_image.height) 128 | self.redraw_image() # 再描画 129 | 130 | def mouse_wheel(self, event): 131 | ''' マウスホイールを回した ''' 132 | if self.pil_image == None: 133 | return 134 | 135 | if event.state != 9: # 9はShiftキー(Windowsの場合だけかも?) 136 | if (event.delta < 0): 137 | # 下に回転の場合、拡大 138 | self.scale_at(1.25, event.x, event.y) 139 | else: 140 | # 上に回転の場合、縮小 141 | self.scale_at(0.8, event.x, event.y) 142 | else: 143 | if (event.delta < 0): 144 | # 下に回転の場合、反時計回り 145 | self.rotate_at(-5, event.x, event.y) 146 | else: 147 | # 上に回転の場合、時計回り 148 | self.rotate_at(5, event.x, event.y) 149 | self.redraw_image() # 再描画 150 | 151 | # ------------------------------------------------------------------------------- 152 | # 画像表示用アフィン変換 153 | # ------------------------------------------------------------------------------- 154 | 155 | def reset_transform(self): 156 | '''アフィン変換を初期化(スケール1、移動なし)に戻す''' 157 | self.mat_affine = np.eye(3) # 3x3の単位行列 158 | 159 | def translate(self, offset_x, offset_y): 160 | ''' 平行移動 ''' 161 | mat = np.eye(3) # 3x3の単位行列 162 | mat[0, 2] = float(offset_x) 163 | mat[1, 2] = float(offset_y) 164 | 165 | self.mat_affine = np.dot(mat, self.mat_affine) 166 | 167 | def scale(self, scale:float): 168 | ''' 拡大縮小 ''' 169 | mat = np.eye(3) # 単位行列 170 | mat[0, 0] = scale 171 | mat[1, 1] = scale 172 | 173 | self.mat_affine = np.dot(mat, self.mat_affine) 174 | 175 | def scale_at(self, scale:float, cx:float, cy:float): 176 | ''' 座標(cx, cy)を中心に拡大縮小 ''' 177 | 178 | # 原点へ移動 179 | self.translate(-cx, -cy) 180 | # 拡大縮小 181 | self.scale(scale) 182 | # 元に戻す 183 | self.translate(cx, cy) 184 | 185 | def rotate(self, deg:float): 186 | ''' 回転 ''' 187 | mat = np.eye(3) # 単位行列 188 | mat[0, 0] = math.cos(math.pi * deg / 180) 189 | mat[1, 0] = math.sin(math.pi * deg / 180) 190 | mat[0, 1] = -mat[1, 0] 191 | mat[1, 1] = mat[0, 0] 192 | 193 | self.mat_affine = np.dot(mat, self.mat_affine) 194 | 195 | def rotate_at(self, deg:float, cx:float, cy:float): 196 | ''' 座標(cx, cy)を中心に回転 ''' 197 | 198 | # 原点へ移動 199 | self.translate(-cx, -cy) 200 | # 回転 201 | self.rotate(deg) 202 | # 元に戻す 203 | self.translate(cx, cy) 204 | 205 | def zoom_fit(self, image_width, image_height): 206 | '''画像をウィジェット全体に表示させる''' 207 | 208 | # キャンバスのサイズ 209 | canvas_width = self.canvas.winfo_width() 210 | canvas_height = self.canvas.winfo_height() 211 | 212 | if (image_width * image_height <= 0) or (canvas_width * canvas_height <= 0): 213 | return 214 | 215 | # アフィン変換の初期化 216 | self.reset_transform() 217 | 218 | scale = 1.0 219 | offsetx = 0.0 220 | offsety = 0.0 221 | 222 | if (canvas_width * image_height) > (image_width * canvas_height): 223 | # ウィジェットが横長(画像を縦に合わせる) 224 | scale = canvas_height / image_height 225 | # あまり部分の半分を中央に寄せる 226 | offsetx = (canvas_width - image_width * scale) / 2 227 | else: 228 | # ウィジェットが縦長(画像を横に合わせる) 229 | scale = canvas_width / image_width 230 | # あまり部分の半分を中央に寄せる 231 | offsety = (canvas_height - image_height * scale) / 2 232 | 233 | # 拡大縮小 234 | self.scale(scale) 235 | # あまり部分を中央に寄せる 236 | self.translate(offsetx, offsety) 237 | 238 | def to_image_point(self, x, y): 239 | ''' キャンバスの座標から画像の座標へ変更 ''' 240 | if self.pil_image == None: 241 | return [] 242 | # 画像→キャンバスの変換からキャンバス→画像にする(逆行列にする) 243 | mat_inv = np.linalg.inv(self.mat_affine) 244 | image_point = np.dot(mat_inv, (x, y, 1.)) 245 | if image_point[0] < 0 or image_point[1] < 0 or image_point[0] > self.pil_image.width or image_point[1] > self.pil_image.height: 246 | return [] 247 | 248 | return image_point 249 | 250 | # ------------------------------------------------------------------------------- 251 | # 描画 252 | # ------------------------------------------------------------------------------- 253 | 254 | def draw_image(self, pil_image): 255 | 256 | if pil_image == None: 257 | return 258 | 259 | self.pil_image = pil_image 260 | 261 | # キャンバスのサイズ 262 | canvas_width = self.canvas.winfo_width() 263 | canvas_height = self.canvas.winfo_height() 264 | 265 | # キャンバスから画像データへのアフィン変換行列を求める 266 | #(表示用アフィン変換行列の逆行列を求める) 267 | mat_inv = np.linalg.inv(self.mat_affine) 268 | 269 | # numpy arrayをアフィン変換用のタプルに変換 270 | affine_inv = ( 271 | mat_inv[0, 0], mat_inv[0, 1], mat_inv[0, 2], 272 | mat_inv[1, 0], mat_inv[1, 1], mat_inv[1, 2] 273 | ) 274 | 275 | # PILの画像データをアフィン変換する 276 | dst = self.pil_image.transform( 277 | (canvas_width, canvas_height),# 出力サイズ 278 | Image.AFFINE, # アフィン変換 279 | affine_inv, # アフィン変換行列(出力→入力への変換行列) 280 | Image.NEAREST # 補間方法、ニアレストネイバー 281 | ) 282 | 283 | im = ImageTk.PhotoImage(image=dst) 284 | 285 | # 画像の描画 286 | item = self.canvas.create_image( 287 | 0, 0, # 画像表示位置(左上の座標) 288 | anchor='nw', # アンカー、左上が原点 289 | image=im # 表示画像データ 290 | ) 291 | 292 | self.image = im 293 | 294 | def redraw_image(self): 295 | ''' 画像の再描画 ''' 296 | if self.pil_image == None: 297 | return 298 | self.draw_image(self.pil_image) 299 | 300 | 301 | if __name__ == "__main__": 302 | root = tk.Tk() 303 | app = Application(master=root) 304 | app.mainloop() 305 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Image Viewer (zoom, pan, rotate) 2 | 3 | ![PythonImageViewer](https://user-images.githubusercontent.com/29155364/106603190-7449bd00-650a-11eb-80f1-b3fe96ba88bf.gif) 4 | 5 | Using module : tkinter, Pilow, math, numpy, os 6 | 7 | | | | 8 | | ------ | ------------------------------ | 9 | | Zoom | Mouse wheel up/down | 10 | | Pan | Mouse left button drag | 11 | | Rotate | Mouse wheel up/down + ShiftKey | 12 | --------------------------------------------------------------------------------