Basic flow

This commit is contained in:
Maddo 2016-11-07 20:58:16 +01:00
commit 15f0d4d5b8
6 changed files with 491 additions and 49 deletions

View file

@ -51,6 +51,7 @@
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="ImageCreator.cs" />
<Compile Include="ImageCreator2.cs" />
<Compile Include="PicSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SinglePicData.cs" />

166
CatalogLib/ImageCreator2.cs Normal file
View file

@ -0,0 +1,166 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CatalogVbLib;
namespace CatalogLib
{
public class ImageCreator2
{
private PicSettings _picSettings = PicSettings.Instance;
private FileInfo _workFile;
private Image _workingImage;
private Rotazione _rotation;
private ImageFormat _currentFormat;
private Size _newImageSize;
private Bitmap _outputImage;
private DirectoryInfo _destDir;
private string _nomeFileBig;
public void Start(FileInfo workFile)
{
_workFile = workFile;
_workingImage = Image.FromFile(workFile.FullName);
_destDir = new DirectoryInfo(_picSettings.DirectoryDestinazione);
_nomeFileBig = _workFile.Name;
CalculateImageSize();
ElaborazioneTesto();
ElaborazioneRotazione();
SetImageFormat();
FinalElaboration();
//CreaMiniature
}
private void FinalElaboration()
{
_outputImage = new Bitmap(_workingImage, _newImageSize.Width, _newImageSize.Height);
_outputImage.SetResolution(_workingImage.HorizontalResolution, _workingImage.VerticalResolution);
SavePic(_outputImage, Path.Combine(_destDir.FullName, _nomeFileBig));
}
private void SavePic(Bitmap imageToSave, string fileName)
{
var selectedEncoder = GetEncoder(_currentFormat);
var encoder = System.Drawing.Imaging.Encoder.Quality;
var encoderParameters = new EncoderParameters(1);
if (Equals(_currentFormat, ImageFormat.Jpeg))
{
var encoderParameter = new EncoderParameter(encoder, _picSettings.CompressioneJpeg);
encoderParameters.Param[0] = encoderParameter;
}
imageToSave.Save(fileName, selectedEncoder,encoderParameters);
imageToSave.Dispose();
}
private ImageCodecInfo GetEncoder(ImageFormat format)
{
var codecs = ImageCodecInfo.GetImageDecoders();
return codecs.FirstOrDefault(c => c.FormatID == format.Guid);
}
private void ElaborazioneTesto()
{
if (_picSettings.EnableText)
{
// todo: elaborazione testo
}
}
private void CalculateImageSize()
{
_newImageSize = new Size(_workingImage.Width, _workingImage.Height);
}
private void ElaborazioneRotazione()
{
_rotation = Rotazione.Normale;
if (_picSettings.UsaRotazioneAutomatica)
{
// ci sono dati exif
if (_workingImage.PropertyIdList.Length > 0)
{
ExifReader DatiExif = new ExifReader((Bitmap)_workingImage);
switch (DatiExif.Orientation)
{
case ExifReader.Orientations.BottomLeft:
break;
case ExifReader.Orientations.BottomRight:
break;
case ExifReader.Orientations.LeftTop:
break;
case ExifReader.Orientations.LftBottom:
//FotoRuotaASinistra = true;
_rotation = Rotazione.Sinistra;
break;
case ExifReader.Orientations.RightBottom:
break;
case ExifReader.Orientations.RightTop:
break;
case ExifReader.Orientations.TopLeft:
break;
case ExifReader.Orientations.TopRight:
break;
}
}
}
if (_rotation == Rotazione.Sinistra)
{
_workingImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
}
else
if (_rotation == Rotazione.Destra)
{
_workingImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
}
}
private void SetImageFormat()
{
_currentFormat = _workingImage.RawFormat;
if (_picSettings.GeneraleForzaJPG)
{
_currentFormat = ImageFormat.Jpeg;
}
}
}
}

View file

@ -15,7 +15,10 @@ namespace CatalogLib
{
private static PicSettings _instance = new PicSettings();
public static PicSettings Instance { get { return _instance; } }
public static PicSettings Instance
{
get { return _instance; }
}
private Dictionary<string, object> _settingsDict = new Dictionary<string, object>();
@ -27,8 +30,13 @@ namespace CatalogLib
public string SerializeSettings()
{
return JsonConvert.SerializeObject(_settingsDict);
}
public void DeserializeSettings(string serializedData)
{
_settingsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(serializedData);
}
public void Set(string key, object value)
@ -43,14 +51,14 @@ namespace CatalogLib
}
}
public void SetString(string key, string value )
public void SetString(string key, string value)
{
Set(key, value);
}
public void SetInt(string key, int value)
{
Set(key,value);
Set(key, value);
}
public void SetBool(string key, bool value)
@ -65,46 +73,84 @@ namespace CatalogLib
return _settingsDict.ContainsKey(key);
}
public int GetInt(string key)
public int GetInt(string key, int defaultValue = 0)
{
return _settingsDict.ContainsKey(key) ? (int)_settingsDict[key] : 0;
}
if (!_settingsDict.ContainsKey(key))
{
SetInt(key, defaultValue);
}
public string GetString(string key)
{
return _settingsDict.ContainsKey(key) ? (string)_settingsDict[key] : string.Empty;
}
if (_settingsDict[key] is int) return (int)_settingsDict[key];
Debug.WriteLine($"Error while parsing {key}");
//return defaultValue;
int r;
public bool GetBool(string key)
{
return _settingsDict.ContainsKey(key) && (bool)_settingsDict[key];
if (int.TryParse(_settingsDict[key].ToString(), out r))
{
SetInt(key, r);
}
else
{
SetInt(key, defaultValue);
}
return (int) _settingsDict[key];
//return (int) _settingsDict[key];
//return _settingsDict.ContainsKey(key) ? (int)_settingsDict[key] : defaultValue;
}
public object GetObject(string key)
public string GetString(string key, string defaultValue = "")
{
return _settingsDict.ContainsKey(key) ? _settingsDict[key] : null;
if (!_settingsDict.ContainsKey(key))
{
SetString(key, defaultValue);
}
return (string) _settingsDict[key];
//return _settingsDict.ContainsKey(key) ? (string)_settingsDict[key] : defaultValue;
}
public bool GetBool(string key, bool defaultValue = false)
{
if (!_settingsDict.ContainsKey(key))
{
SetBool(key, defaultValue);
return defaultValue;
}
return (bool) _settingsDict[key];
//return _settingsDict.ContainsKey(key) && (bool)_settingsDict[key];
}
public object GetObject(string key, object defaultValue = null)
{
if (!_settingsDict.ContainsKey(key))
{
Set(key, defaultValue);
return defaultValue;
}
return _settingsDict[key];
//return _settingsDict.ContainsKey(key) ? _settingsDict[key] : defaultValue;
}
public void SetDefaults()
{
//Set("DirSorgente", string.Empty);
//Set("DirDestinazione", string.Empty);
//Set("DirAggiornaSottodirectory", false);
//Set("DirCreaSottoCartelle", false);
//Set();
}
public bool DirAggiornaSottoDirectory
{
get { return this.GetBool("DirAggiornaSottoDirectory"); }
set
{
this.SetBool("DirAggiornaSottoDirectory", value);
}
get { return this.GetBool("DirAggiornaSottoDirectory", true); }
set { this.SetBool("DirAggiornaSottoDirectory", value); }
}
public bool Grassetto
@ -187,14 +233,121 @@ namespace CatalogLib
public string TestoFirmaStart { get; set; }
public string TestoFirmaStartV { get; set; }
public bool UsaForzaJpg { get; set; }
public string DirectorySorgente { get { return GetString("DirSorgente"); } set { SetString("DirSorgente", value); } }
public string DirectoryDestinazione { get { return GetString("DirDestinazione"); } set { SetString("DirDestinazione", value);} }
public string DirectorySorgente
{
get { return GetString("DirSorgente"); }
set { SetString("DirSorgente", value); }
}
public string DirectoryDestinazione
{
get { return GetString("DirDestinazione"); }
set { SetString("DirDestinazione", value); }
}
public float Margine { get; set; }
public float MargVert { get; set; }
public string Allineamento { get; set; }
public bool GeneraleForzaJPG { get { return GetBool("GeneraleForzaJPG"); } set { SetBool("GeneraleForzaJPG", value);} }
public bool GeneraleRotazioneAutomatica { get { return GetBool("GeneraleRotazioneAutomatica"); } set { SetBool("GeneraleRotazioneAutomatica", value); } }
public bool GeneraleSovrascriviFile { get { return GetBool("GeneraleSovrascriviFile"); } set { SetBool("GeneraleSovrascriviFile", value); } }
public bool GeneraleForzaJPG
{
get { return GetBool("GeneraleForzaJPG", true); }
set { SetBool("GeneraleForzaJPG", value); }
}
public bool GeneraleRotazioneAutomatica
{
get { return GetBool("GeneraleRotazioneAutomatica"); }
set { SetBool("GeneraleRotazioneAutomatica", value); }
}
public bool GeneraleSovrascriviFile
{
get { return GetBool("GeneraleSovrascriviFile"); }
set { SetBool("GeneraleSovrascriviFile", value); }
}
public bool SubdirCreaSottoCartelle
{
get { return GetBool("SubdirCreaSottoCartelle"); }
set { SetBool("SubdirCreaSottoCartelle", value); }
}
public int SubdirIntervalloFile
{
get { return GetInt("SubdirIntervalloFile", 99); }
set { SetInt("SubdirIntervalloFile", value); }
}
public string SubdirSuffisso
{
get { return GetString("SubdirSuffisso"); }
set { SetString("SubdirSuffisso", value); }
}
public int SubdirCifreContatore
{
get { return GetInt("SubdirCifreContatore", 2); }
set { SetInt("SubdirCifreContatore", value); }
}
public bool SubdirNumerazioneProgressiva
{
get { return GetBool("SubdirNumerazioneProgressiva", true); }
set { SetBool("SubdirNumerazioneProgressiva", value); }
}
public bool SubdirNumerazioneFiles
{
get { return GetBool("SubdirNumerazioneFiles", false); }
set { SetBool("SubdirNumerazioneFiles", value); }
}
public int FotoAltezza
{
get { return GetInt("FotoAltezza", 2240); }
set { SetInt("FotoAltezza", value); }
}
public int FotoLarghezza
{
get { return GetInt("FotoLarghezza", 2240); }
set { SetInt("FotoLarghezza", value); }
}
public int CompressioneJpeg
{
get { return GetInt("CompressioneJpeg", 85); }
set { SetInt("CompressioneJpeg", value); }
}
public bool FotoMantieniDimensioni
{
get { return GetBool("FotoMantieniDimensioni", true); }
set { SetBool("FotoMantieniDimensioni", value); }
}
public string FotoSuffisso
{
get { return GetString("FotoSuffisso"); }
set { SetString("FotoSuffisso", value); }
}
public bool EnableText
{
get { return GetBool("EnableText", false); }
set { SetBool("EnableText", value); }
}
public bool EnableThumbnails
{
get { return GetBool("EnableThumbnails", false); }
set { SetBool("EnableThumbnails", value); }
}
public bool EnableLogo
{
get { return GetBool("EnableLogo", false); }
set { SetBool("EnableLogo", value); }
}
}
}
}

@ -1 +1 @@
Subproject commit e5db4a03bbb6404b34ec679126503941b2fffa4c
Subproject commit e44a21295ec64e8b9caa22a9eb22af18fac6f7e6

View file

@ -101,7 +101,7 @@
</GroupBox>
<GroupBox Header="Generale" Margin="2">
<StackPanel Orientation="Vertical" >
<CheckBox Content="Aggiorna JPG" x:Name="chkForzaJPG" IsChecked="{Binding GeneraleForzaJPG}" Margin="2"/>
<CheckBox Content="Forza JPG" x:Name="chkForzaJPG" IsChecked="{Binding GeneraleForzaJPG}" Margin="2"/>
<CheckBox Content="Rotazione Automatica" x:Name="chkRotazioneAutomatica" IsChecked="{Binding GeneraleRotazioneAutomatica}" Margin="2"/>
<CheckBox Content="Sovrascrivi File" x:Name="chkSovrascriviFile" IsChecked="{Binding GeneraleSovrascriviFile}" Margin="2"/>
</StackPanel>
@ -170,7 +170,16 @@
<TextBox Grid.Row="1" Grid.Column="2" Width="80" Margin="4,2,4,6" Text="{Binding FotoLarghezza}"></TextBox>
<Label Grid.Row="1" Grid.Column="0" Content="Qualità" Grid.ColumnSpan="2" Margin="0,24,0,1" Grid.RowSpan="2" />
<TextBox Grid.Row="2" Grid.Column="2" Width="80" Margin="4,2,4,5" />
<!--<TextBox Grid.Row="2" Grid.Column="2" Width="80" Margin="4,2,4,5" />-->
<Grid Grid.Row="2" Grid.Column="2" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Slider Grid.Column="0" Orientation="Horizontal" Maximum="100" Minimum="0" Value="{Binding CompressioneJpeg}"></Slider>
<TextBlock Grid.Column="1" Text="{Binding CompressioneJpeg}"></TextBlock>
</Grid>
<CheckBox Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,16,0,17.88" IsChecked="{Binding FotoMantieniDimensioni}"/>
<TextBlock Grid.Row="3" Grid.Column="2" Text="Mantieni Dimensioni Originali" TextWrapping="WrapWithOverflow" Width="80" Margin="4,0,4,25.88" Grid.RowSpan="2" />
@ -429,7 +438,7 @@
<Button Content="Carica Impostazioni" Command="{Binding ImportSettingsCommand}"></Button>
<Button Content="Salva Impostazioni" Command="{Binding ExportSettingsCommand}" ></Button>
</StackPanel>
<Button Content="Start"></Button>
<Button Content="Start" Command="{Binding StartCommand}"></Button>
<Button Content="STOP" Command="{Binding StopCommand}"/>
</StackPanel>
</GroupBox>

View file

@ -31,21 +31,40 @@ namespace WPFCatalog
#region commands
public RelayCommand ExportSettingsCommand { get; private set; }
public RelayCommand ImportSettingsCommand { get; private set; }
public RelayCommand SelectSourceFolderCommand { get; private set; }
public RelayCommand SelectDestinationFolderCommand { get; private set; }
public RelayCommand OpenSourceFolderCommand { get; private set; }
public RelayCommand OpenDestinationFolderCommand { get; private set; }
public RelayCommand StartCommand { get; private set; }
private void RegisterCommands()
{
ExportSettingsCommand = new RelayCommand(ExportSettings);
ImportSettingsCommand = new RelayCommand(ImportSettings);
SelectSourceFolderCommand = new RelayCommand(SelectSourceFolder);
OpenSourceFolderCommand = new RelayCommand(OpenSourceFolder);
SelectDestinationFolderCommand = new RelayCommand(SelectDestinationFolder);
OpenDestinationFolderCommand = new RelayCommand(OpenDestinationFolder);
StartCommand = new RelayCommand(Start);
}
private void Start()
{
//var files = Directory.GetFiles(PicSettings.DirectorySorgente);
foreach (var file in Directory.EnumerateFiles(PicSettings.DirectorySorgente))
{
ImageCreator2 i = new ImageCreator2();
i.Start(new FileInfo(file));
}
DialogHelper.PopUpAlert("Finished", "message");
}
private void OpenSourceFolder()
@ -73,7 +92,7 @@ namespace WPFCatalog
if (!string.IsNullOrWhiteSpace(a))
{
this.DirSorgente = a;
}
}
@ -93,7 +112,28 @@ namespace WPFCatalog
string s = PicSettings.SerializeSettings();
DialogHelper.PopUpAlert(s, "data");
var savePath = FileHelper.GetSavePath("", "settings.json", string.Empty);
if (string.IsNullOrWhiteSpace(savePath)) return;
if (Directory.Exists(Path.GetDirectoryName(savePath)))
{
Debug.WriteLine(savePath);
FileHelper.WriteToFile(savePath, s);
Debug.WriteLine(s);
}
}
private void ImportSettings()
{
var loadPath = FileHelper.GetOpenPath();
if (string.IsNullOrWhiteSpace(loadPath)) return;
if (File.Exists(loadPath))
{
var f = FileHelper.ReadTextFile(loadPath);
PicSettings.DeserializeSettings(f);
RaisePropertyChanged(string.Empty);
}
}
#endregion
@ -133,9 +173,38 @@ namespace WPFCatalog
public bool SubdirCreaSottoCartelle
{
get { return true; }
set { }// temp
//get { return PicSettings.GetBool("")}
get { return PicSettings.SubdirCreaSottoCartelle; }
set { PicSettings.SubdirCreaSottoCartelle = value; RaisePropertyChanged("SubdirCreaSottoCartelle"); }
}
public int SubdirIntervalloFile
{
get { return PicSettings.SubdirIntervalloFile; }
set { PicSettings.SubdirIntervalloFile = value; RaisePropertyChanged("SubdirIntervalloFile"); }
}
public string SubdirSuffisso
{
get { return PicSettings.SubdirSuffisso; }
set { PicSettings.SubdirSuffisso = value; RaisePropertyChanged("SubdirSuffisso"); }
}
public int SubdirCifreContatore
{
get { return PicSettings.SubdirCifreContatore; }
set { PicSettings.SubdirCifreContatore = value; RaisePropertyChanged("SubdirCifreContatore"); }
}
public bool SubdirNumerazioneProgressiva
{
get { return PicSettings.SubdirNumerazioneProgressiva; }
set { PicSettings.SubdirNumerazioneProgressiva = value; RaisePropertyChanged("SubdirNumerazioneProgressiva"); }
}
public bool SubdirNumerazioneFiles
{
get { return PicSettings.SubdirNumerazioneFiles; }
set { PicSettings.SubdirNumerazioneFiles = value; RaisePropertyChanged("SubdirNumerazioneFiles"); }
}
public string DirDividiNumFile { get { return PicSettings.GetString("dirDividiNumFile"); } set { PicSettings.Set("dirDividiNumFile", value); } }
@ -146,7 +215,7 @@ namespace WPFCatalog
public bool DirDividiTipoNumerazioneFile { get { return PicSettings.GetString("DirDividiTipoNumerazione").ToUpper() == "FILES"; } set { if (value == false) PicSettings.Set("DirDividiTipoNumerazione", "FILES"); } }
public bool MiniatureCrea { get { return PicSettings.GetBool("miniatureCrea"); } set { PicSettings.Set("miniatureCrea", value); RaisePropertyChanged("MiniatureCrea"); } }
public string MiniatureSuffisso
{
@ -198,22 +267,25 @@ namespace WPFCatalog
}
}
public string FotoAltezza
public int FotoAltezza
{
get { return PicSettings.GetString("fotoAltezza"); }
get
{
return PicSettings.FotoAltezza;
}
set
{
PicSettings.Set("fotoAltezza", value);
PicSettings.FotoAltezza = value;
RaisePropertyChanged("FotoAltezza");
}
}
public string FotoLarghezza
public int FotoLarghezza
{
get { return PicSettings.GetString("fotoLarghezza"); }
get { return PicSettings.FotoLarghezza; }
set
{
PicSettings.Set("fotoLarghezza", value);
PicSettings.FotoLarghezza = value;
RaisePropertyChanged("FotoLarghezza");
}
}
@ -539,16 +611,32 @@ namespace WPFCatalog
}
}
public string CompressioneJpeg
public int CompressioneJpeg
{
get { return PicSettings.GetString("compressioneJpeg"); }
get { return PicSettings.CompressioneJpeg; }
set
{
PicSettings.Set("compressioneJpeg", value);
PicSettings.CompressioneJpeg = value;
RaisePropertyChanged("CompressioneJpeg");
}
}
public bool FotoMantieniDimensioni
{
get { return PicSettings.FotoMantieniDimensioni; }
set
{
PicSettings.FotoMantieniDimensioni = value;
RaisePropertyChanged("FotoMantieniDimensioni");
}
}
public string FotoSuffisso
{
get { return PicSettings.FotoSuffisso; }
set { PicSettings.FotoSuffisso = value; RaisePropertyChanged("FotoSuffisso"); }
}
public string CompressioneJpegMiniatura
{
get { return PicSettings.GetString("compressioneJpegMiniatura"); }
@ -571,6 +659,31 @@ namespace WPFCatalog
#endregion
#region Testo
public bool EnableText
{
get { return PicSettings.EnableText; }
set { PicSettings.EnableText = value; RaisePropertyChanged("EnableText");}
}
public bool EnableThumbnails
{
get { return PicSettings.EnableThumbnails; }
set { PicSettings.EnableThumbnails = value; RaisePropertyChanged("EnableThumbnails"); }
}
public bool EnableLogo
{
get { return PicSettings.EnableLogo; }
set { PicSettings.EnableLogo = value; RaisePropertyChanged("EnableLogo"); }
}
#endregion