Commit 717b5284 by liulongfei

图片对比工具

parent e3bab2c1
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<Application x:Class="VIZ.Framework.ImageContrastTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VIZ.Framework.ImageContrastTool"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Module;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
public App()
{
// 缓存数据库
AppSetup.AppendSetup(new AppSetup_InitLiteDb());
// 执行启动流程
AppSetupContext context = AppSetup.Setup();
if (context.Exception != null)
{
MessageBox.Show($"执行 {context.ProviderDetail} 失败\r\n{context.Exception.Message}");
}
if (!context.IsSuccess)
{
Environment.Exit(-1);
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 路径转化为文件名的额转化器
/// </summary>
public class PathToFileNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string path = value as string;
if (string.IsNullOrWhiteSpace(path))
return null;
return System.IO.Path.GetFileName(path);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using OpenCvSharp;
using OpenCvSharp.WpfExtensions;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 路径转图片转化器
/// </summary>
public class PathToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string path = value as string;
if (string.IsNullOrWhiteSpace(path))
return null;
if (!System.IO.File.Exists(path))
return null;
Mat mat = new Mat(path);
var result = mat.ToBitmapSource();
mat.Dispose();
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Domain;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 应用程序域
/// </summary>
public class ApplicationDomainEx : ApplicationDomain
{
/// <summary>
/// 缓存上下文
/// </summary>
public static LiteDbContext LiteDbContext { get; set; }
}
}
<Window x:Class="VIZ.Framework.ImageContrastTool.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VIZ.Framework.ImageContrastTool"
mc:Ignorable="d" WindowStartupLocation="CenterScreen"
Title="图片对比工具" Height="600" Width="1200">
<Grid>
<local:MainView Margin="10"></local:MainView>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Module;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
this.Closed += MainWindow_Closed;
}
/// <summary>
/// 窗口加载
/// </summary>
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// 執行加载流程
AppSetupContext context = AppSetup.Load();
if (context.Exception != null)
{
MessageBox.Show($"执行 {context.ProviderDetail} 失败\r\n{context.Exception.Message}");
}
if (!context.IsSuccess)
{
Environment.Exit(-1);
}
}
/// <summary>
/// 窗口关闭
/// </summary>
private void MainWindow_Closed(object sender, EventArgs e)
{
// 卸载
AppSetup.UnLoad();
// 停止
AppSetup.ShutDown();
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("VIZ.Framework.ImageContrastTool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VIZ.Framework.ImageContrastTool")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//例如,如果您在源文件中使用的是美国英语,
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace VIZ.Framework.ImageContrastTool.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VIZ.Framework.ImageContrastTool.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace VIZ.Framework.ImageContrastTool.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
\ No newline at end of file
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Module;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 应用程序启动 -- 初始化LiteDb
/// </summary>
public class AppSetup_InitLiteDb : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_InitLiteDb));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 初始化LiteDb";
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
string floder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "db");
if (!System.IO.Directory.Exists(floder))
{
System.IO.Directory.CreateDirectory(floder);
}
string path = System.IO.Path.Combine(floder, "cache.db");
ApplicationDomainEx.LiteDbContext = new LiteDbContext(path);
// 初始化系统配置
this.initSystemConfig();
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
ApplicationDomainEx.LiteDbContext?.Dispose();
ApplicationDomainEx.LiteDbContext = null;
}
/// <summary>
/// 初始化系统配置
/// </summary>
private void initSystemConfig()
{
SystemConfig config = ApplicationDomainEx.LiteDbContext.SystemConfigs.FindAll().FirstOrDefault();
if (config == null)
{
config = new SystemConfig();
ApplicationDomainEx.LiteDbContext.SystemConfigs.Insert(config);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using LiteDB;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// LiteDB数据上下文
/// </summary>
public class LiteDbContext : IDisposable
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(LiteDbContext));
/// <summary>
/// 数据库
/// </summary>
private ILiteDatabase Database;
/// <summary>
/// LiteDB数据库
/// </summary>
/// <param name="path">数据库路径</param>
public LiteDbContext(string path)
{
this.Path = path;
this.Database = new LiteDatabase(path);
this.SystemConfigs = this.Database.GetCollection<SystemConfig>();
}
// -----------------------------------------------------------------------------------------------------------
// -- OpenCV --
// -----------------------------------------------------------------------------------------------------------
/// <summary>
/// 数据库文件路径
/// </summary>
public string Path { get; private set; }
/// <summary>
/// 视频分组
/// </summary>
public ILiteCollection<SystemConfig> SystemConfigs { get; private set; }
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
this.SystemConfigs = null;
this.Database?.Dispose();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 系统配置
/// </summary>
public class SystemConfig
{
/// <summary>
/// 编号
/// </summary>
[LiteDB.BsonId(true)]
public int ID { get; set; }
/// <summary>
/// 左侧路径
/// </summary>
public string LeftPath { get; set; }
/// <summary>
/// 右侧路径
/// </summary>
public string RightPath { get; set; }
}
}
<UserControl x:Class="VIZ.Framework.ImageContrastTool.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VIZ.Framework.ImageContrastTool"
xmlns:common="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
d:DataContext="{d:DesignInstance Type=local:MainViewModel}"
mc:Ignorable="d" Background="White"
d:DesignHeight="450" d:DesignWidth="1400">
<UserControl.Resources>
<local:PathToImageConverter x:Key="PathToImageConverter"></local:PathToImageConverter>
<local:PathToFileNameConverter x:Key="PathToFileNameConverter"></local:PathToFileNameConverter>
</UserControl.Resources>
<behaviors:Interaction.Triggers>
<behaviors:EventTrigger EventName="Loaded">
<behaviors:InvokeCommandAction Command="{Binding LoadedCommand}" />
</behaviors:EventTrigger>
</behaviors:Interaction.Triggers>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="100"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="图片列表" Margin="5">
<ListBox Margin="5" ItemsSource="{Binding Path=ImageFiles,Mode=OneWay}"
SelectedValue="{Binding Path=SelectedImageFile,Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .,Converter={StaticResource PathToFileNameConverter}}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
<GroupBox Header="Left" Margin="5" Grid.Column="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="120"></ColumnDefinition>
</Grid.ColumnDefinitions>
<common:LabelValue Label="图片文件夹路径" Text="{Binding LeftPath}" ToolTip="{Binding LeftPath}"
Height="30" Margin="5,0,5,0"></common:LabelValue>
<Button Grid.Column="1" Width="100" Height="30" Content="选择图片文件夹" Command="{Binding Path=SelectLeftPathCommand}"></Button>
</Grid>
<Image Grid.Row="1" Stretch="Uniform" Source="{Binding Path=SelectedImageFile,Converter={StaticResource PathToImageConverter}}"></Image>
</Grid>
</GroupBox>
<GroupBox Header="Right" Grid.Column="2" Margin="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="120"></ColumnDefinition>
</Grid.ColumnDefinitions>
<common:LabelValue Label="图片文件夹路径" Text="{Binding RightPath}" ToolTip="{Binding RightPath}"
Height="30" Margin="5,0,5,0"></common:LabelValue>
<Button Grid.Column="1" Width="100" Height="30" Content="选择图片文件夹" Command="{Binding SelectRightPathCommand}"></Button>
</Grid>
<Image Grid.Row="1" Stretch="Uniform" Source="{Binding Path=RightImageFile,Converter={StaticResource PathToImageConverter}}"></Image>
</Grid>
</GroupBox>
<GroupBox Header="控制" Grid.Row="1" Grid.ColumnSpan="3" Margin="5">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Width="120" Height="40" Content="刷新" Margin="5" Command="{Binding RefreshCommand}"></Button>
<Rectangle Width="2" Fill="#ffd5dfe5" Margin="20,0,20,0" Height="40"></Rectangle>
<Button Width="120" Height="40" Content="上一张" Margin="5" Command="{Binding PrevCommand}"></Button>
<Button Width="120" Height="40" Content="下一张" Margin="5" Command="{Binding NextCommand}"></Button>
</StackPanel>
</GroupBox>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new MainViewModel());
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VIZ.Framework.Core;
using OpenCvSharp;
using OpenCvSharp.WpfExtensions;
namespace VIZ.Framework.ImageContrastTool
{
/// <summary>
/// 主视图模型
/// </summary>
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
// 初始化命令
this.InitCommand();
}
/// <summary>
/// 初始化命令
/// </summary>
private void InitCommand()
{
this.LoadedCommand = new VCommand(this.Loaded);
this.SelectLeftPathCommand = new VCommand(this.SelectLeftPath);
this.SelectRightPathCommand = new VCommand(this.SelectRightPath);
this.RefreshCommand = new VCommand(this.Refresh);
this.NextCommand = new VCommand(this.Next);
this.PrevCommand = new VCommand(this.Prev);
}
// --------------------------------------------------------------------
// Field
// --------------------------------------------------------------------
/// <summary>
/// 系统配置
/// </summary>
private SystemConfig systemConfig;
// --------------------------------------------------------------------
// Property
// --------------------------------------------------------------------
#region LeftPath -- 左侧图片文件夹路径
private string leftPath;
/// <summary>
/// 左侧图片文件夹路径
/// </summary>
public string LeftPath
{
get { return leftPath; }
set { leftPath = value; this.RaisePropertyChanged(nameof(LeftPath)); }
}
#endregion
#region RightPath -- 右侧图片文件夹路径
private string rightPath;
/// <summary>
/// 右侧图片文件夹路径
/// </summary>
public string RightPath
{
get { return rightPath; }
set { rightPath = value; this.RaisePropertyChanged(nameof(RightPath)); }
}
#endregion
#region ImageFiles -- 图片文件集合
private List<string> imageFiles;
/// <summary>
/// 图片文件集合
/// </summary>
public List<string> ImageFiles
{
get { return imageFiles; }
set { imageFiles = value; this.RaisePropertyChanged(nameof(ImageFiles)); }
}
#endregion
#region SelectedImageFile -- 当前选中的图片值
private string selectedImageFile;
/// <summary>
/// 当前选中的图片值
/// </summary>
public string SelectedImageFile
{
get { return selectedImageFile; }
set
{
selectedImageFile = value;
this.RaisePropertyChanged(nameof(SelectedImageFile));
this.UpdateRightImageFile();
}
}
#endregion
#region RightImageFile -- 右侧图片路径
private string rightImageFile;
/// <summary>
/// 右侧图片路径
/// </summary>
public string RightImageFile
{
get { return rightImageFile; }
set { rightImageFile = value; this.RaisePropertyChanged(nameof(RightImageFile)); }
}
#endregion
// --------------------------------------------------------------------
// Command
// --------------------------------------------------------------------
#region LoadedCommand -- 加载命令
/// <summary>
/// 加载命令
/// </summary>
public VCommand LoadedCommand { get; set; }
/// <summary>
/// 加载
/// </summary>
private void Loaded()
{
this.systemConfig = ApplicationDomainEx.LiteDbContext.SystemConfigs.FindAll().FirstOrDefault();
this.LeftPath = this.systemConfig.LeftPath;
this.RightPath = this.systemConfig.RightPath;
}
#endregion
#region SelectLeftPathCommand -- 选择左侧图片文件夹路径命令
/// <summary>
/// 选择左侧图片文件夹路径命令
/// </summary>
public VCommand SelectLeftPathCommand { get; set; }
/// <summary>
/// 选择左侧图片文件夹路径
/// </summary>
private void SelectLeftPath()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() != DialogResult.OK)
return;
this.LeftPath = fbd.SelectedPath;
this.systemConfig.LeftPath = this.LeftPath;
ApplicationDomainEx.LiteDbContext.SystemConfigs.Update(this.systemConfig);
}
#endregion
#region SelectRightPathCommand -- 选择右侧图片文件夹路径命令
/// <summary>
/// 选择右侧图片文件夹路径命令
/// </summary>
public VCommand SelectRightPathCommand { get; set; }
/// <summary>
/// 选择右侧图片文件夹路径
/// </summary>
private void SelectRightPath()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() != DialogResult.OK)
return;
this.RightPath = fbd.SelectedPath;
this.systemConfig.RightPath = this.RightPath;
ApplicationDomainEx.LiteDbContext.SystemConfigs.Update(this.systemConfig);
}
#endregion
#region RefreshCommand -- 刷新命令
/// <summary>
/// 刷新命令
/// </summary>
public VCommand RefreshCommand { get; set; }
/// <summary>
/// 刷新
/// </summary>
private void Refresh()
{
if (System.IO.Directory.Exists(this.LeftPath))
{
this.ImageFiles = System.IO.Directory.GetFiles(this.LeftPath, "*.jpg").ToList();
}
else
{
this.ImageFiles = null;
}
this.SelectedImageFile = null;
this.RightImageFile = null;
}
#endregion
#region NextCommand -- 下一张命令
/// <summary>
/// 下一张命令
/// </summary>
public VCommand NextCommand { get; set; }
/// <summary>
/// 下一张
/// </summary>
private void Next()
{
if (this.SelectedImageFile == null)
{
this.SelectedImageFile = this.ImageFiles.FirstOrDefault();
}
else
{
int index = this.ImageFiles.IndexOf(this.SelectedImageFile);
++index;
if (index <= this.ImageFiles.Count - 1)
{
this.SelectedImageFile = this.ImageFiles[index];
}
}
}
#endregion
#region PrevCommand -- 上一张命令
/// <summary>
/// 上一张命令
/// </summary>
public VCommand PrevCommand { get; set; }
/// <summary>
/// 上一张
/// </summary>
private void Prev()
{
if (this.SelectedImageFile == null)
{
this.SelectedImageFile = this.ImageFiles.FirstOrDefault();
}
else
{
int index = this.ImageFiles.IndexOf(this.SelectedImageFile);
--index;
if (index >= 0)
{
this.SelectedImageFile = this.ImageFiles[index];
}
}
}
#endregion
// --------------------------------------------------------------------
// Private Function
// --------------------------------------------------------------------
/// <summary>
/// 更新右侧图片路径
/// </summary>
private void UpdateRightImageFile()
{
if (string.IsNullOrWhiteSpace(this.SelectedImageFile))
{
this.RightImageFile = null;
return;
}
string fileName = System.IO.Path.GetFileName(this.SelectedImageFile);
this.RightImageFile = System.IO.Path.Combine(this.RightPath, fileName);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LiteDB" version="5.0.12" targetFramework="net48" />
<package id="log4net" version="2.0.14" targetFramework="net48" />
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.39" targetFramework="net48" />
<package id="OpenCvSharp4" version="4.6.0.20220608" targetFramework="net48" />
<package id="OpenCvSharp4.WpfExtensions" version="4.6.0.20220608" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.4" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
</packages>
\ No newline at end of file
......@@ -48,6 +48,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "80-Tool", "80-Tool", "{4E1C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VIZ.Framework.UDPTestTool", "VIZ.Framework.UDPTestTool\VIZ.Framework.UDPTestTool.csproj", "{6DDCBD19-6E92-4363-A509-9820562FC048}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VIZ.Framework.ImageContrastTool", "VIZ.Framework.ImageContrastTool\VIZ.Framework.ImageContrastTool.csproj", "{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -94,48 +96,56 @@ Global
{B62C822E-701F-480F-BBB1-0E02217D622C}.Debug|x64.Build.0 = Debug|x64
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|Any CPU.Build.0 = Release|Any CPU
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|x64.ActiveCfg = Release|Any CPU
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|x64.Build.0 = Release|Any CPU
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|x64.ActiveCfg = Release|x64
{B62C822E-701F-480F-BBB1-0E02217D622C}.Release|x64.Build.0 = Release|x64
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Debug|x64.ActiveCfg = Debug|x64
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Debug|x64.Build.0 = Debug|x64
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|Any CPU.Build.0 = Release|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|x64.ActiveCfg = Release|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|x64.Build.0 = Release|Any CPU
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|x64.ActiveCfg = Release|x64
{E07528DD-9DEE-47C2-B79D-235ECFA6B003}.Release|x64.Build.0 = Release|x64
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Debug|x64.ActiveCfg = Debug|x64
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Debug|x64.Build.0 = Debug|x64
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|Any CPU.Build.0 = Release|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|x64.ActiveCfg = Release|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|x64.Build.0 = Release|Any CPU
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|x64.ActiveCfg = Release|x64
{76EF480A-E486-41B7-B7A5-2A849FC8D5BF}.Release|x64.Build.0 = Release|x64
{F9862446-B144-42F1-87A4-FAF3707268A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Debug|x64.ActiveCfg = Debug|x64
{F9862446-B144-42F1-87A4-FAF3707268A6}.Debug|x64.Build.0 = Debug|x64
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|Any CPU.Build.0 = Release|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|x64.ActiveCfg = Release|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|x64.Build.0 = Release|Any CPU
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|x64.ActiveCfg = Release|x64
{F9862446-B144-42F1-87A4-FAF3707268A6}.Release|x64.Build.0 = Release|x64
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Debug|x64.ActiveCfg = Debug|x64
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Debug|x64.Build.0 = Debug|x64
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|Any CPU.Build.0 = Release|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|x64.ActiveCfg = Release|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|x64.Build.0 = Release|Any CPU
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|x64.ActiveCfg = Release|x64
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892}.Release|x64.Build.0 = Release|x64
{6DDCBD19-6E92-4363-A509-9820562FC048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Debug|x64.ActiveCfg = Debug|x64
{6DDCBD19-6E92-4363-A509-9820562FC048}.Debug|x64.Build.0 = Debug|x64
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|Any CPU.Build.0 = Release|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|x64.ActiveCfg = Release|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|x64.Build.0 = Release|Any CPU
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|x64.ActiveCfg = Release|x64
{6DDCBD19-6E92-4363-A509-9820562FC048}.Release|x64.Build.0 = Release|x64
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Debug|x64.ActiveCfg = Debug|x64
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Debug|x64.Build.0 = Debug|x64
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Release|Any CPU.Build.0 = Release|Any CPU
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Release|x64.ActiveCfg = Release|x64
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -151,6 +161,7 @@ Global
{F9862446-B144-42F1-87A4-FAF3707268A6} = {C78D0841-72DB-4ED7-B200-2E7F20D9D6BA}
{47CF6FB0-E37D-4EF1-AFC7-03DB2BCA8892} = {5EB5F581-9DF6-4166-AC5B-89E6851089E9}
{6DDCBD19-6E92-4363-A509-9820562FC048} = {4E1CA052-91A6-401D-9F07-4973231A33FB}
{70D6EBC7-0C32-4A52-BFD2-6D20219FC608} = {4E1CA052-91A6-401D-9F07-4973231A33FB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4C56D4BA-4B41-4AB8-836F-9997506EA9AC}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment