Commit b04eed5c authored by Боев Андрей Олегович's avatar Боев Андрей Олегович
Browse files

add preparation for the photo processing process

parent 22e7b5c3
No related merge requests found
Showing with 68 additions and 27 deletions
+68 -27
......@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ReadySetPrint"
mc:Ignorable="d"
Title="ReadySetPrint" Height="400" Width="640" ResizeMode="NoResize" Icon="/logo.png">
Title="ReadySetPrint" Height="500" Width="640" ResizeMode="NoResize" Icon="/logo.png">
<StackPanel HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal">
<Button Content="Выбрать папку" Width="100" Margin="5" Name="BtnChooseFolder" Click="BtnChooseFolder_Click"></Button>
......@@ -13,7 +13,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Расположение:" VerticalAlignment="Center" Margin="5"></TextBlock>
<ComboBox Width="100" Margin="5" SelectedIndex="0" Name="CBPosition" SelectionChanged="CBPosition_SelectionChanged">
<ComboBox Width="100" Margin="5" SelectedIndex="0" Name="CBPosition">
<ComboBoxItem Content="center"></ComboBoxItem>
<ComboBoxItem Content="top"></ComboBoxItem>
<ComboBoxItem Content="bottom"></ComboBoxItem>
......@@ -26,34 +26,16 @@
<StackPanel Orientation="Horizontal">
<StackPanel>
<TextBlock Text="Исходные фото:" Margin="5 5 5 0"></TextBlock>
<ListView Margin="5" Width="300" Height="191" Name="LVOriginalPhotos">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Margin="5"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Margin="5" Width="300" Height="291" Name="LVOriginalPhotos"></ListView>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="Обработанные фото:" Margin="5 5 5 0"></TextBlock>
<ListView Margin="5" Width="300" Height="80">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Margin="5"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Margin="5" Width="300" Height="130" Name="LVReadyPhotos"></ListView>
<TextBlock Text="Отбракованные фото:" Margin="5 5 5 0"></TextBlock>
<ListView Margin="5" Width="300" Height="80">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Margin="5"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Margin="5" Width="300" Height="130" Name="LVDefectPhotos"></ListView>
</StackPanel>
</StackPanel>
<Button Content="Обработать изображения" Margin="5" Height="30"></Button>
<Button Content="Обработать изображения" Margin="5" Height="30" Name="BtnStartProcess" Click="BtnStartProcess_Click"></Button>
<ProgressBar Name="PBStatus" Margin="5" Height="20"></ProgressBar>
</StackPanel>
</Window>
......@@ -12,8 +12,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
//using ImageMagick;
namespace ReadySetPrint
......@@ -33,11 +33,25 @@ namespace ReadySetPrint
private void BtnChooseFolder_Click(object sender, RoutedEventArgs e)
{
using (var dlg = new FolderBrowserDialog())
using (var dlg = new System.Windows.Forms.FolderBrowserDialog())
{
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_folderPath = dlg.SelectedPath;
var images = Directory.GetFiles(_folderPath, "*.*")
.Where(f => f.EndsWith(".jpg") || f.EndsWith(".png"))
.ToList();
if (images.Count == 0)
{
MessageBox.Show("В папке отсутствуют фото в формате .png или .jpg", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
_folderPath = "";
return;
}
foreach (var image in images)
{
LVOriginalPhotos.Items.Add(image.Replace(_folderPath + "\\", ""));
}
TBPath.Text = "Путь: " + dlg.SelectedPath;
}
}
......@@ -45,7 +59,7 @@ namespace ReadySetPrint
private void BtnChooseColor_Click(object sender, RoutedEventArgs e)
{
using (ColorDialog dlg = new ColorDialog())
using (var dlg = new System.Windows.Forms.ColorDialog())
{
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
......@@ -54,5 +68,50 @@ namespace ReadySetPrint
}
}
}
private void BtnStartProcess_Click(object sender, RoutedEventArgs e)
{
if (_folderPath == "")
{
MessageBox.Show("Выберите папку с изображениями.");
return;
}
BtnChooseColor.IsEnabled = false;
BtnChooseFolder.IsEnabled = false;
BtnStartProcess.IsEnabled = false;
PBStatus.Value = 0;
var images = Directory.GetFiles(_folderPath, "*.*")
.Where(f => f.EndsWith(".jpg") || f.EndsWith(".png"))
.ToList();
float progress = 100 / images.Count;
foreach (var image in images)
{
bool result = ImageProcess(image, CBPosition.Text);
if (result)
LVReadyPhotos.Items.Add(image.Replace(_folderPath + "\\", ""));
else
LVDefectPhotos.Items.Add(image.Replace(_folderPath + "\\", ""));
PBStatus.Value += progress;
}
MessageBox.Show("Обработка завершена.", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
BtnChooseColor.IsEnabled = true;
BtnChooseFolder.IsEnabled = true;
BtnStartProcess.IsEnabled = true;
}
private bool ImageProcess(string path, string position)
{
try
{
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
}
}
}
Supports Markdown
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