├── .gitignore ├── License.txt ├── Logo ├── MagickViewer.icon.svg └── MagickViewer.svg ├── MagickViewer.ruleset ├── MagickViewer.sln ├── MagickViewer ├── .editorconfig ├── App.xaml ├── App.xaml.cs ├── ClickOnce │ ├── Index.html │ └── PublishClickOnce.targets ├── Controls │ ├── ImageViewer.cs │ ├── Logo.cs │ └── MouseCapture.cs ├── EventArgs │ └── LoadedEventArgs.cs ├── Extensions │ ├── FileInfoExtensions.cs │ └── FrameworkElementExtensions.cs ├── ImageIterator.cs ├── ImageManager.cs ├── Magick.NET.snk ├── MagickViewer.csproj ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Resources │ ├── Fonts │ │ └── OpenSans-Bold.ttf │ ├── Icons │ │ ├── MagickViewer.ico │ │ └── MagickViewer.png │ ├── Notice.txt │ └── Themes │ │ ├── Dark │ │ ├── Close.png │ │ ├── Close.svg │ │ ├── Loading.png │ │ ├── Loading.svg │ │ ├── Menu.png │ │ ├── Menu.svg │ │ ├── Minimize.png │ │ ├── Minimize.svg │ │ └── Theme.xaml │ │ ├── Merged.xaml │ │ └── Shared │ │ └── Shared.xaml ├── app.config └── packages.config ├── Readme.md └── stylecop.json /.gitignore: -------------------------------------------------------------------------------- 1 |  2 | /MagickViewer/bin 3 | /MagickViewer/obj 4 | /MagickViewer/*.user 5 | /*.suo 6 | /packages 7 | /Publish 8 | /.vs 9 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Logo/MagickViewer.icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 25 | 29 | 30 | 33 | 37 | 38 | 41 | 45 | 46 | 55 | 59 | 63 | 64 | 71 | 73 | 75 | 77 | 79 | 84 | 85 | 86 | 87 | 88 | 89 | 100 | 101 | 120 | 122 | 123 | 125 | image/svg+xml 126 | 128 | 129 | 130 | 131 | 132 | 137 | 141 | 144 | 149 | 150 | 153 | 158 | 159 | 162 | 167 | 168 | 170 | 173 | 175 | 177 | 179 | 183 | 185 | 188 | 190 | 192 | 195 | 197 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 215 | 220 | 221 | 224 | 229 | 230 | 233 | 238 | 239 | 240 | 241 | 242 | -------------------------------------------------------------------------------- /Logo/MagickViewer.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 22 | 25 | 29 | 30 | 32 | 36 | 41 | 42 | 46 | 51 | 52 | 56 | 61 | 62 | 66 | 71 | 72 | 76 | 81 | 82 | 86 | 91 | 92 | 96 | 101 | 102 | 106 | 111 | 112 | 116 | 121 | 122 | 126 | 131 | 132 | 136 | 141 | 142 | 146 | 151 | 152 | 156 | 161 | 162 | 166 | 171 | 172 | 176 | 181 | 182 | 186 | 191 | 192 | 196 | 201 | 202 | 206 | 211 | 212 | 216 | 221 | 222 | 226 | 231 | 232 | 236 | 241 | 242 | 246 | 251 | 252 | 256 | 261 | 262 | 266 | 271 | 272 | 273 | 274 | 292 | 294 | 295 | 297 | image/svg+xml 298 | 300 | 301 | 302 | 303 | 304 | 309 | 312 | 317 | 322 | 327 | 332 | 337 | 342 | 345 | 352 | 359 | 366 | 373 | 380 | 387 | 394 | 401 | 408 | 415 | 422 | 429 | 430 | 433 | 440 | 447 | 454 | 461 | 468 | 475 | 482 | 489 | 496 | 503 | 510 | 517 | 524 | 531 | 538 | 545 | 552 | 553 | 554 | 555 | 556 | -------------------------------------------------------------------------------- /MagickViewer.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /MagickViewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34202.233 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagickViewer", "MagickViewer\MagickViewer.csproj", "{1DFF1171-E594-4E79-AC1C-2DBC394A0CA2}" 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 | {1DFF1171-E594-4E79-AC1C-2DBC394A0CA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1DFF1171-E594-4E79-AC1C-2DBC394A0CA2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1DFF1171-E594-4E79-AC1C-2DBC394A0CA2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1DFF1171-E594-4E79-AC1C-2DBC394A0CA2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {7AC41FE6-DE3F-4CBA-B718-5E462DC0146A} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MagickViewer/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | indent_style = space 4 | insert_final_newline = true 5 | trim_trailing_whitespace = true 6 | 7 | [*.{config,csproj,md,xaml}] 8 | 9 | indent_size = 2 10 | tab_width = 2 11 | 12 | [*.cs] 13 | 14 | indent_size = 4 15 | tab_width = 4 16 | 17 | [*.cs] 18 | 19 | csharp_prefer_simple_using_statement = false 20 | csharp_prefer_static_local_function = true: rror 21 | 22 | dotnet_sort_system_directives_first = true:error 23 | 24 | csharp_style_implicit_object_creation_when_type_is_apparent = false:error 25 | 26 | csharp_style_pattern_matching_over_as_with_null_check = true:error 27 | 28 | csharp_style_prefer_range_operator = false 29 | dotnet_style_prefer_simplified_boolean_expressions = true:error 30 | csharp_style_prefer_switch_expression = true:error 31 | 32 | dotnet_style_predefined_type_for_locals_parameters_members = true:error 33 | 34 | dotnet_style_qualification_for_event = false:error 35 | dotnet_style_qualification_for_field = false:error 36 | dotnet_style_qualification_for_method = false:error 37 | dotnet_style_qualification_for_property = false:error 38 | 39 | csharp_style_var_for_built_in_types = true:error 40 | csharp_style_var_when_type_is_apparent = true:error 41 | csharp_style_var_elsewhere = true:error 42 | 43 | csharp_style_unused_value_assignment_preference = true:error 44 | 45 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion 46 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 47 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 48 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field 49 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private 50 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 51 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 52 | -------------------------------------------------------------------------------- /MagickViewer/App.xaml: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /MagickViewer/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System.Windows; 5 | 6 | namespace MagickViewer 7 | { 8 | public partial class App : Application 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /MagickViewer/ClickOnce/Index.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | [ProductName] 4 | 5 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 95 | 96 |
60 | 61 | 62 |
 
Name:[ProductName]
 
Version:[ApplicationVersion]
 
Publisher:[PublisherName]
 
63 | 64 | 65 | 66 |
The following prerequisites are required:
 
    67 | [Prerequisites] 68 |
69 | If these components are already installed, you can launch the application now. Otherwise, click the button below to install the prerequisites and run the application. 70 |
 
71 | 72 | 73 | 74 |
75 | 76 |
Install
 
87 | 88 |
89 | [PublisherName] Customer Support 90 |    ::    91 | ClickOnce and .NET Framework Resources 92 |
93 | 94 |
97 | 98 | -------------------------------------------------------------------------------- /MagickViewer/ClickOnce/PublishClickOnce.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | @(FilteredBootstrapperPackage->'<LI>%(ProductName)</LI>', '') 36 | 37 | 38 | 46 | 47 | -------------------------------------------------------------------------------- /MagickViewer/Controls/ImageViewer.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Input; 8 | using System.Windows.Media; 9 | 10 | namespace MagickViewer.Controls 11 | { 12 | internal sealed class ImageViewer : ScrollViewer 13 | { 14 | public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageViewer), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnImageSourceChanged))); 15 | 16 | public static readonly DependencyProperty LoadingImageSourceProperty = DependencyProperty.Register("LoadingImageSource", typeof(ImageSource), typeof(ImageViewer), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); 17 | 18 | private MouseCapture _capture; 19 | private bool _fitToScreen = true; 20 | 21 | public ImageViewer() 22 | : base() 23 | { 24 | PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown; 25 | PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp; 26 | PreviewMouseMove += OnPreviewMouseMove; 27 | } 28 | 29 | public ImageSource ImageSource 30 | { 31 | get => (ImageSource)GetValue(ImageSourceProperty); 32 | set => SetValue(ImageSourceProperty, value); 33 | } 34 | 35 | public ImageSource LoadingImageSource 36 | { 37 | get => (ImageSource)GetValue(LoadingImageSourceProperty); 38 | set => SetValue(LoadingImageSourceProperty, value); 39 | } 40 | 41 | private Image Image => (Image)Content; 42 | 43 | public void HideLoadingImage() 44 | { 45 | ImageSource = null; 46 | Image.Source = null; 47 | Image.Style = (Style)FindResource("Image"); 48 | } 49 | 50 | public override void OnApplyTemplate() 51 | { 52 | base.OnApplyTemplate(); 53 | CreateImage(); 54 | LayoutUpdated += OnLayoutUpdated; 55 | } 56 | 57 | public void ShowLoadingImage() 58 | { 59 | Image.Style = (Style)FindResource("ImageLoading"); 60 | Image.Source = LoadingImageSource; 61 | Image.BeginStoryboard("Rotate"); 62 | } 63 | 64 | protected override void OnKeyDown(KeyEventArgs arguments) 65 | { 66 | // Disable KeyDown on the ImageViewer. 67 | } 68 | 69 | private static void OnImageSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs arguments) 70 | { 71 | var target = sender as ImageViewer; 72 | if (target == null) 73 | return; 74 | 75 | var source = (ImageSource)arguments.NewValue; 76 | if (source == null) 77 | return; 78 | 79 | target.Image.Source = source; 80 | target.SetImageSize(); 81 | } 82 | 83 | private void CreateImage() 84 | { 85 | var image = new Image 86 | { 87 | Style = (Style)FindResource("Image") 88 | }; 89 | 90 | Content = image; 91 | UpdateImageSize(); 92 | } 93 | 94 | private void OnLayoutUpdated(object sender, EventArgs e) 95 | => UpdateImageSize(); 96 | 97 | private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs arguments) 98 | { 99 | var target = sender as ScrollViewer; 100 | if (target == null) 101 | return; 102 | 103 | _capture = new MouseCapture(target, arguments); 104 | 105 | if (arguments.ClickCount == 2) 106 | ToggleFitToScreen(); 107 | } 108 | 109 | private void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs arguments) 110 | { 111 | var target = sender as ScrollViewer; 112 | if (target == null) 113 | return; 114 | 115 | target.ReleaseMouseCapture(); 116 | _capture = null; 117 | } 118 | 119 | private void OnPreviewMouseMove(object sender, MouseEventArgs arguments) 120 | { 121 | if (_capture == null) 122 | return; 123 | 124 | if (arguments.LeftButton != MouseButtonState.Pressed) 125 | return; 126 | 127 | var target = sender as ScrollViewer; 128 | if (target == null) 129 | return; 130 | 131 | var point = arguments.GetPosition(target); 132 | 133 | var dx = point.X - _capture.Point.X; 134 | var dy = point.Y - _capture.Point.Y; 135 | if (Math.Abs(dy) > 5 || Math.Abs(dx) > 5) 136 | target.CaptureMouse(); 137 | 138 | target.ScrollToHorizontalOffset(_capture.HorizontalOffset - dx); 139 | target.ScrollToVerticalOffset(_capture.VerticalOffset - dy); 140 | } 141 | 142 | private void SetImageSize() 143 | { 144 | if (_fitToScreen) 145 | { 146 | UpdateImageSize(); 147 | } 148 | else if (Image.Source != null) 149 | { 150 | Image.Width = Image.Source.Width; 151 | Image.Height = Image.Source.Height; 152 | } 153 | } 154 | 155 | private void ToggleFitToScreen() 156 | { 157 | _fitToScreen = !_fitToScreen; 158 | Image.Stretch = _fitToScreen ? Stretch.Uniform : Stretch.None; 159 | SetImageSize(); 160 | } 161 | 162 | private void UpdateImageSize() 163 | { 164 | if (!_fitToScreen || Image.Source == null) 165 | return; 166 | 167 | Image.Width = ActualWidth > Image.Source.Width ? Image.Source.Width : ActualWidth; 168 | Image.Height = ActualHeight > Image.Source.Height ? Image.Source.Height : ActualHeight; 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /MagickViewer/Controls/Logo.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System.Diagnostics; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Input; 8 | 9 | namespace MagickViewer.Controls 10 | { 11 | internal sealed class Logo : Control 12 | { 13 | public static readonly RoutedEvent ClickEvent = EventManager.RegisterRoutedEvent( 14 | "Click", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Logo)); 15 | 16 | static Logo() 17 | { 18 | DefaultStyleKeyProperty.OverrideMetadata(typeof(Logo), new FrameworkPropertyMetadata(typeof(Logo))); 19 | EventManager.RegisterClassHandler(typeof(Logo), Mouse.MouseDownEvent, new MouseButtonEventHandler(OnMouseDown)); 20 | } 21 | 22 | public event RoutedEventHandler Click 23 | { 24 | add => AddHandler(ClickEvent, value); 25 | remove => RemoveHandler(ClickEvent, value); 26 | } 27 | 28 | private static void OnMouseDown(object sender, MouseButtonEventArgs arguments) 29 | { 30 | if (arguments.OriginalSource is Image) 31 | RaiseMouseDown(sender as Logo); 32 | else 33 | OpenWebsite(); 34 | 35 | arguments.Handled = true; 36 | } 37 | 38 | private static void OpenWebsite() 39 | => Process.Start(new ProcessStartInfo("https://github.com/dlemstra/MagickViewer")); 40 | 41 | private static void RaiseMouseDown(Logo sender) 42 | { 43 | var eventArgs = new RoutedEventArgs(Logo.ClickEvent); 44 | sender.RaiseEvent(eventArgs); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MagickViewer/Controls/MouseCapture.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Input; 7 | 8 | namespace MagickViewer.Controls 9 | { 10 | internal sealed class MouseCapture 11 | { 12 | public MouseCapture(ScrollViewer scrollViewer, MouseButtonEventArgs arguments) 13 | { 14 | VerticalOffset = scrollViewer.VerticalOffset; 15 | HorizontalOffset = scrollViewer.HorizontalOffset; 16 | Point = arguments.GetPosition(scrollViewer); 17 | } 18 | 19 | public double HorizontalOffset { get; } 20 | 21 | public Point Point { get; } 22 | 23 | public double VerticalOffset { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MagickViewer/EventArgs/LoadedEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System; 5 | using ImageMagick; 6 | 7 | namespace MagickViewer 8 | { 9 | internal sealed class LoadedEventArgs : EventArgs 10 | { 11 | public LoadedEventArgs() 12 | { 13 | } 14 | 15 | public LoadedEventArgs(MagickErrorException exception) 16 | => Exception = exception; 17 | 18 | public MagickErrorException Exception { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /MagickViewer/Extensions/FileInfoExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Threading; 8 | using ImageMagick; 9 | 10 | namespace MagickViewer 11 | { 12 | internal static class FileInfoExtensions 13 | { 14 | public static bool IsSupported(this FileInfo self) 15 | { 16 | if (self == null || string.IsNullOrEmpty(self.FullName)) 17 | return false; 18 | 19 | if (self.Name.Length < 2) 20 | return false; 21 | 22 | if (string.IsNullOrEmpty(self.Extension)) 23 | return false; 24 | 25 | if (!Enum.TryParse(self.Extension.Substring(1), true, out MagickFormat format)) 26 | return false; 27 | 28 | return (from formatInfo in MagickNET.SupportedFormats 29 | where formatInfo.SupportsReading && formatInfo.Format == format 30 | select formatInfo).Any(); 31 | } 32 | 33 | public static bool WaitForAccess(this FileInfo file) 34 | { 35 | var hasAccess = false; 36 | while (!hasAccess) 37 | { 38 | try 39 | { 40 | using (var stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)) 41 | { 42 | hasAccess = true; 43 | } 44 | } 45 | catch (IOException) 46 | { 47 | } 48 | 49 | if (!hasAccess) 50 | Thread.Sleep(100); 51 | } 52 | 53 | return true; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MagickViewer/Extensions/FrameworkElementExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System.Windows; 5 | using System.Windows.Media.Animation; 6 | 7 | namespace MagickViewer 8 | { 9 | internal static class FrameworkElementExtensions 10 | { 11 | public static void BeginStoryboard(this FrameworkElement self, string resourceKey) 12 | { 13 | if (self == null) 14 | return; 15 | 16 | var storyboard = self.FindResource(resourceKey) as Storyboard; 17 | if (storyboard == null) 18 | return; 19 | 20 | Storyboard.SetTarget(storyboard, self); 21 | storyboard.Begin(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MagickViewer/ImageIterator.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System; 5 | using System.IO; 6 | using System.Linq; 7 | 8 | namespace MagickViewer 9 | { 10 | internal sealed class ImageIterator 11 | { 12 | public FileInfo Current { get; set; } 13 | 14 | internal FileInfo Next() 15 | { 16 | if (Current == null) 17 | return null; 18 | 19 | var files = GetSupportedFiles(); 20 | if (files.Length == 1) 21 | return null; 22 | 23 | for (var i = 0; i < files.Length; i++) 24 | { 25 | if (IsCurrent(files[i])) 26 | { 27 | i++; 28 | if (i == files.Length) 29 | i = 0; 30 | return files[i]; 31 | } 32 | } 33 | 34 | return null; 35 | } 36 | 37 | internal FileInfo Previous() 38 | { 39 | if (Current == null) 40 | return null; 41 | 42 | var files = GetSupportedFiles(); 43 | if (files.Length == 1) 44 | return null; 45 | 46 | for (var i = files.Length - 1; i >= 0; i--) 47 | { 48 | if (IsCurrent(files[i])) 49 | { 50 | i--; 51 | if (i == -1) 52 | i = files.Length - 1; 53 | return files[i]; 54 | } 55 | } 56 | 57 | return null; 58 | } 59 | 60 | private FileInfo[] GetSupportedFiles() 61 | { 62 | return (from file in Current.Directory.GetFiles() 63 | where file.IsSupported() 64 | select file).ToArray(); 65 | } 66 | 67 | private bool IsCurrent(FileInfo file) 68 | => Current.FullName.Equals(file.FullName, StringComparison.OrdinalIgnoreCase); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /MagickViewer/ImageManager.cs: -------------------------------------------------------------------------------- 1 | // Copyright Dirk Lemstra https://github.com/dlemstra/MagickViewer. 2 | // Licensed under the Apache License, Version 2.0. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Threading; 9 | using System.Windows.Threading; 10 | using ImageMagick; 11 | using Microsoft.Win32; 12 | 13 | namespace MagickViewer 14 | { 15 | internal sealed class ImageManager : IDisposable 16 | { 17 | private static readonly object _Semaphore = new object(); 18 | private static readonly string[] _GhostscriptFormats = new string[] 19 | { 20 | ".EPS", ".PDF", ".PS" 21 | }; 22 | 23 | private Dispatcher _dispatcher; 24 | private FileSystemWatcher _watcher; 25 | private ImageIterator _imageIterator; 26 | private int _index; 27 | private MagickImageCollection _images; 28 | private OpenFileDialog _openDialog; 29 | private SaveFileDialog _saveDialog; 30 | 31 | public ImageManager(Dispatcher dispatcher) 32 | { 33 | _dispatcher = dispatcher; 34 | 35 | Initialize(); 36 | } 37 | 38 | public event EventHandler Loading; 39 | 40 | public event EventHandler Loaded; 41 | 42 | public string FileInfo 43 | { 44 | get 45 | { 46 | if (_imageIterator.Current == null) 47 | return null; 48 | 49 | var fileInfo = _imageIterator.Current.FullName; 50 | 51 | if (_images != null) 52 | { 53 | if (_images.Count > 1) 54 | fileInfo += $" ({_index + 1} of {_images.Count})"; 55 | 56 | if (Image != null) 57 | fileInfo += $" {Image.Format.ToString().ToUpperInvariant()} {Image.Width}x{Image.Height}"; 58 | } 59 | 60 | return fileInfo; 61 | } 62 | } 63 | 64 | public IMagickImage Image 65 | { 66 | get 67 | { 68 | if (_images.Count == 0) 69 | return null; 70 | 71 | return _images[_index]; 72 | } 73 | } 74 | 75 | public static bool IsSupported(string fileName) 76 | => new FileInfo(fileName).IsSupported(); 77 | 78 | public void Dispose() 79 | { 80 | DisposeImages(); 81 | DisposeWatcher(); 82 | } 83 | 84 | public void Load(string fileName) 85 | => Load(new FileInfo(fileName)); 86 | 87 | public void ShowOpenDialog() 88 | { 89 | if (_openDialog.ShowDialog() != true) 90 | return; 91 | 92 | Load(_openDialog.FileName); 93 | } 94 | 95 | public void ShowSaveDialog() 96 | { 97 | if (_saveDialog.ShowDialog() != true) 98 | return; 99 | 100 | Save(_saveDialog.FileName); 101 | } 102 | 103 | public void Next() 104 | { 105 | var file = _imageIterator.Next(); 106 | if (file != null) 107 | Load(file); 108 | } 109 | 110 | public void NextFrame() 111 | { 112 | if (_images.Count < 2) 113 | return; 114 | 115 | if (++_index == _images.Count) 116 | _index = 0; 117 | 118 | OnFrameChanged(); 119 | } 120 | 121 | public void Optimize() 122 | { 123 | var imageOptimizer = new ImageOptimizer 124 | { 125 | OptimalCompression = true 126 | }; 127 | 128 | imageOptimizer.LosslessCompress(_imageIterator.Current); 129 | } 130 | 131 | public void Previous() 132 | { 133 | var file = _imageIterator.Previous(); 134 | if (file != null) 135 | Load(file); 136 | } 137 | 138 | public void PreviousFrame() 139 | { 140 | if (_images.Count < 2) 141 | return; 142 | 143 | if (--_index == -1) 144 | _index = _images.Count - 1; 145 | 146 | OnFrameChanged(); 147 | } 148 | 149 | private static string CreateFilter(IEnumerable formats) 150 | { 151 | var formatNames = from formatInfo in formats 152 | orderby formatInfo.Format 153 | select formatInfo.Format.ToString().ToLowerInvariant(); 154 | 155 | var formatDescriptions = from formatInfo in formats 156 | orderby formatInfo.Description 157 | group formatInfo.Format by formatInfo.Description into g 158 | select g.Key + "|*." + string.Join(";*.", g).ToLowerInvariant(); 159 | 160 | var filter = "All supported formats (...)|*." + string.Join(";*.", formatNames); 161 | 162 | filter += "|" + string.Join("|", formatDescriptions); 163 | 164 | return filter; 165 | } 166 | 167 | private void ConstructImages() 168 | { 169 | DisposeImages(); 170 | 171 | _images = new MagickImageCollection(); 172 | _index = 0; 173 | } 174 | 175 | private void DisposeImages() 176 | { 177 | if (_images == null) 178 | return; 179 | 180 | _images.Dispose(); 181 | _images = null; 182 | } 183 | 184 | private void DisposeWatcher() 185 | { 186 | if (_watcher != null) 187 | { 188 | _watcher.Dispose(); 189 | _watcher = null; 190 | } 191 | } 192 | 193 | private void Initialize() 194 | { 195 | _imageIterator = new ImageIterator(); 196 | 197 | _watcher = new FileSystemWatcher(); 198 | _watcher.Changed += OnFileChanged; 199 | 200 | _openDialog = new OpenFileDialog(); 201 | SetOpenFilter(); 202 | 203 | _saveDialog = new SaveFileDialog(); 204 | SetSaveFilter(); 205 | } 206 | 207 | private void Load(FileInfo file) 208 | { 209 | Monitor.Enter(_Semaphore); 210 | 211 | _imageIterator.Current = file; 212 | 213 | _watcher.Path = file.DirectoryName; 214 | _watcher.Filter = file.Name; 215 | _watcher.EnableRaisingEvents = true; 216 | 217 | OnLoading(); 218 | 219 | var thread = new Thread(() => ReadImage(file)); 220 | thread.Start(); 221 | } 222 | 223 | private void OnFileChanged(object sender, FileSystemEventArgs arguments) 224 | { 225 | _watcher.EnableRaisingEvents = false; 226 | 227 | _imageIterator.Current.WaitForAccess(); 228 | 229 | _dispatcher.Invoke((Action)(() => Load(_imageIterator.Current))); 230 | } 231 | 232 | private void OnFrameChanged() 233 | { 234 | if (Loaded == null) 235 | return; 236 | 237 | _dispatcher.Invoke((Action)(() => Loaded(this, new LoadedEventArgs()))); 238 | } 239 | 240 | private void OnLoaded(MagickErrorException exception) 241 | { 242 | if (Loaded == null) 243 | return; 244 | 245 | _dispatcher.Invoke((Action)(() => 246 | { 247 | Loaded(this, new LoadedEventArgs(exception)); 248 | Monitor.Exit(_Semaphore); 249 | })); 250 | } 251 | 252 | private void OnLoading() 253 | { 254 | if (Loading == null) 255 | return; 256 | 257 | _dispatcher.Invoke((Action)(() => Loading(this, EventArgs.Empty))); 258 | } 259 | 260 | private void ReadImage(FileInfo file) 261 | { 262 | var previousIndex = int.MaxValue; 263 | if (file.FullName == _images?.FirstOrDefault()?.FileName) 264 | previousIndex = _index; 265 | 266 | ConstructImages(); 267 | 268 | MagickErrorException exception = null; 269 | 270 | try 271 | { 272 | var settings = new MagickReadSettings(); 273 | if (_GhostscriptFormats.Contains(file.Extension.ToUpperInvariant())) 274 | settings.Density = new Density(300); 275 | 276 | _images.Read(file, settings); 277 | 278 | if (previousIndex < _images.Count) 279 | _index = previousIndex; 280 | } 281 | catch (MagickErrorException ex) 282 | { 283 | exception = ex; 284 | } 285 | 286 | OnLoaded(exception); 287 | } 288 | 289 | private void Save(string fileName) 290 | => _images.Write(fileName); 291 | 292 | private void SetOpenFilter() 293 | { 294 | var formats = from formatInfo in MagickNET.SupportedFormats 295 | where formatInfo.SupportsReading 296 | select formatInfo; 297 | 298 | _openDialog.Filter = CreateFilter(formats); 299 | } 300 | 301 | private void SetSaveFilter() 302 | { 303 | var formats = from formatInfo in MagickNET.SupportedFormats 304 | where formatInfo.SupportsWriting 305 | select formatInfo; 306 | 307 | _saveDialog.Filter = CreateFilter(formats); 308 | } 309 | } 310 | } 311 | -------------------------------------------------------------------------------- /MagickViewer/Magick.NET.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dlemstra/MagickViewer/deafebf69203d5486984751f5a90ab3334b9fd2a/MagickViewer/Magick.NET.snk -------------------------------------------------------------------------------- /MagickViewer/MagickViewer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1DFF1171-E594-4E79-AC1C-2DBC394A0CA2} 8 | WinExe 9 | Properties 10 | MagickViewer 11 | MagickViewer 12 | v4.8 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | true 17 | 18 | 19 | ..\Publish\ 20 | true 21 | Web 22 | true 23 | Foreground 24 | 7 25 | Days 26 | false 27 | true 28 | true 29 | http://magickviewer.azurewebsites.net/ 30 | http://magickviewer.azurewebsites.net/ 31 | https://github.com/dlemstra/MagickViewer 32 | MagickViewer 33 | Dirk Lemstra 34 | Magick.NET 35 | 13.3.0.0 36 | true 37 | index.html 38 | false 39 | 0 40 | 13.3.0.0 41 | false 42 | true 43 | true 44 | true 45 | 46 | 47 | x64 48 | true 49 | full 50 | false 51 | bin\Debug\ 52 | DEBUG;TRACE 53 | prompt 54 | 4 55 | ..\MagickViewer.ruleset 56 | false 57 | 58 | 59 | x64 60 | pdbonly 61 | true 62 | bin\Release\ 63 | TRACE 64 | prompt 65 | 4 66 | ..\MagickViewer.ruleset 67 | true 68 | false 69 | 70 | 71 | Resources\Icons\MagickViewer.ico 72 | 73 | 74 | true 75 | 76 | 77 | Magick.NET.snk 78 | 79 | 80 | A444A3261489C9F9D311928643A8EBAEF65B0F6C 81 | 82 | 83 | 84 | 85 | 86 | 87 | true 88 | 89 | 90 | true 91 | 92 | 93 | http://timestamp.digicert.com 94 | 95 | 96 | 97 | ..\packages\Magick.NET-Q16-x64.13.3.0\lib\netstandard20\Magick.NET-Q16-x64.dll 98 | 99 | 100 | ..\packages\Magick.NET.Core.13.3.0\lib\netstandard20\Magick.NET.Core.dll 101 | 102 | 103 | ..\packages\Magick.NET.SystemWindowsMedia.7.1.0\lib\net462\Magick.NET.SystemWindowsMedia.dll 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 4.0 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | MSBuild:Compile 123 | Designer 124 | 125 | 126 | MSBuild:Compile 127 | Designer 128 | 129 | 130 | App.xaml 131 | Code 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | MainWindow.xaml 142 | Code 143 | 144 | 145 | MSBuild:Compile 146 | Designer 147 | 148 | 149 | Designer 150 | MSBuild:Compile 151 | 152 | 153 | MSBuild:Compile 154 | Designer 155 | 156 | 157 | 158 | 159 | 160 | Code 161 | 162 | 163 | True 164 | True 165 | Resources.resx 166 | 167 | 168 | True 169 | Settings.settings 170 | True 171 | 172 | 173 | PublicResXFileCodeGenerator 174 | Resources.Designer.cs 175 | 176 | 177 | MagickViewer.ruleset 178 | 179 | 180 | stylecop.json 181 | 182 | 183 | 184 | 185 | 186 | 187 | SettingsSingleFileGenerator 188 | Settings.Designer.cs 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | False 216 | Microsoft .NET Framework 4.8 %28x86 and x64%29 217 | true 218 | 219 | 220 | False 221 | .NET Framework 3.5 SP1 222 | false 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /MagickViewer/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  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 |