Clean up
This commit is contained in:
parent
5d21d3f8ef
commit
1cd71c54fc
5 changed files with 964 additions and 886 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
@ -13,6 +14,7 @@ using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace MaddoShared
|
namespace MaddoShared
|
||||||
{
|
{
|
||||||
|
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
|
||||||
public class ImageCreationStuff(ILogger<ImageCreationStuff> logger, PicSettings picSettings, ImageCreatorSharp imageCreatorService)
|
public class ImageCreationStuff(ILogger<ImageCreationStuff> logger, PicSettings picSettings, ImageCreatorSharp imageCreatorService)
|
||||||
{
|
{
|
||||||
public class Options
|
public class Options
|
||||||
|
|
@ -38,11 +40,9 @@ namespace MaddoShared
|
||||||
{
|
{
|
||||||
var stopwatch = new Stopwatch();
|
var stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
// todo immagini counter
|
|
||||||
//todo set label
|
|
||||||
await ProcessImagesParallel(options, results, updateEvent, cancellationToken);
|
await ProcessImagesParallel(options, results, updateEvent, cancellationToken);
|
||||||
|
|
||||||
// todo set finito label
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -55,7 +55,7 @@ namespace MaddoShared
|
||||||
EventHandler<Tuple<string, int>> updateEvent,
|
EventHandler<Tuple<string, int>> updateEvent,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
List<FileData> dataToProcess = GetFilesToProcess(options);
|
var dataToProcess = GetFilesToProcess(options);
|
||||||
|
|
||||||
// int threads = options.MaxThreads == 0 ? Environment.ProcessorCount * 2 : options.MaxThreads;
|
// int threads = options.MaxThreads == 0 ? Environment.ProcessorCount * 2 : options.MaxThreads;
|
||||||
int threads = options.MaxThreads;
|
int threads = options.MaxThreads;
|
||||||
|
|
@ -179,158 +179,7 @@ namespace MaddoShared
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async Task CreaImmaginiParallel(Options options, ConcurrentBag<string> results,
|
private static IEnumerable<List<T>> SplitList<T>(List<T> bigList, int nSize = 3)
|
||||||
// EventHandler<Tuple<string, int>> updateEvent,
|
|
||||||
// CancellationToken cancellationToken = default(CancellationToken))
|
|
||||||
// {
|
|
||||||
// var dataToProcess = new List<FileData>();
|
|
||||||
// if (options.AggiornaSottodirectory && options.CreaSottocartelle)
|
|
||||||
// {
|
|
||||||
// var helper = new FileHelperSharp();
|
|
||||||
// dataToProcess = helper.GetFilesRecursive(new DirectoryInfo(options.SourcePath),
|
|
||||||
// new DirectoryInfo(options.DestinationPath),
|
|
||||||
// "*.jpg", new FileHelperOptions()
|
|
||||||
// {
|
|
||||||
// FilesPerFolder = options.FilePerCartella,
|
|
||||||
// Suffix = options.SuffissoCartelle,
|
|
||||||
// CounterSize = options.CifreContatore,
|
|
||||||
// NumerationType = options.NumerazioneType
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// else if (!options.CreaSottocartelle)
|
|
||||||
// {
|
|
||||||
// var files = Directory.EnumerateFiles(options.SourcePath, "*.jpg",
|
|
||||||
// options.AggiornaSottodirectory
|
|
||||||
// ? SearchOption.AllDirectories
|
|
||||||
// : SearchOption.TopDirectoryOnly);
|
|
||||||
//
|
|
||||||
// dataToProcess = files.Select(x =>
|
|
||||||
// {
|
|
||||||
// var fInfo = new FileInfo(x);
|
|
||||||
// var filePath = fInfo.DirectoryName;
|
|
||||||
// var trimmedSourcePath = options.SourcePath.TrimEnd('\\');
|
|
||||||
// var newFilePath = fInfo.FullName.Replace(trimmedSourcePath, "").TrimStart('\\');
|
|
||||||
// newFilePath = Path.Combine(options.DestinationPath, newFilePath);
|
|
||||||
//
|
|
||||||
// var destFolderPath = new FileInfo(newFilePath).DirectoryName;
|
|
||||||
// var destFolderInfo = new DirectoryInfo(destFolderPath);
|
|
||||||
// destFolderInfo.EnsureDirectoryExists();
|
|
||||||
//
|
|
||||||
// return new FileData(fInfo, new DirectoryInfo(new FileInfo(newFilePath).DirectoryName));
|
|
||||||
// }).ToList();
|
|
||||||
//
|
|
||||||
// //// TODO
|
|
||||||
// //dataToProcess =
|
|
||||||
// // (from f in Directory.EnumerateFiles(options.SourcePath, "*.jpg",
|
|
||||||
// // options.AggiornaSottodirectory
|
|
||||||
// // ? SearchOption.AllDirectories
|
|
||||||
// // : SearchOption.TopDirectoryOnly)
|
|
||||||
// // select new FileData(new FileInfo(f),
|
|
||||||
// // new DirectoryInfo(options.DestinationPath.PathCombine(
|
|
||||||
// // new FileInfo(f).DirectoryName.Replace(options.SourcePath.TrimEnd(new char[] {'\\'}), "")
|
|
||||||
// // )
|
|
||||||
// // )
|
|
||||||
// // )
|
|
||||||
// // )
|
|
||||||
// // .ToList();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var threads = options.MaxThreads == 0 ? Environment.ProcessorCount * 2 : options.MaxThreads;
|
|
||||||
// var scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, threads)
|
|
||||||
// .ConcurrentScheduler;
|
|
||||||
//
|
|
||||||
// //var allTasks = new List<Task>();
|
|
||||||
// var test = from d in dataToProcess
|
|
||||||
// select Task.Factory.StartNew(async () =>
|
|
||||||
// {
|
|
||||||
// var imgCreator = new ImageCreatorSharp(d.File, d.Directory);
|
|
||||||
// await imgCreator.CreaImmagineThread(d.File.Name);
|
|
||||||
//
|
|
||||||
// //await new ImageCreatorSharp(d.File, d.Directory).CreaImmagineThread(d.File.Name);
|
|
||||||
//
|
|
||||||
// imgCreator = null;
|
|
||||||
//
|
|
||||||
// //var imgC = new ImageCreatorSharp(d.File, d.Directory);
|
|
||||||
// //imgC.CreaImmagineThread(d.File.Name);
|
|
||||||
// //imgC = null;
|
|
||||||
// }, CancellationToken.None, TaskCreationOptions.None, scheduler);
|
|
||||||
//
|
|
||||||
// //int count = 0;
|
|
||||||
//
|
|
||||||
// if (options.LinearExecution)
|
|
||||||
// {
|
|
||||||
// foreach (var task in test)
|
|
||||||
// {
|
|
||||||
// await task;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (options.ChunksSize == 0)
|
|
||||||
// {
|
|
||||||
// //var opts = new ParallelOptions() { MaxDegreeOfParallelism = threads, CancellationToken = cancellationToken, TaskScheduler = scheduler};
|
|
||||||
// await dataToProcess.ParallelForEachAsync(async fileData =>
|
|
||||||
// {
|
|
||||||
// var imgCreator = new ImageCreatorSharp(fileData.File, fileData.Directory);
|
|
||||||
// await imgCreator.CreaImmagineThread(fileData.File.Name);
|
|
||||||
// // await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(fileData.File.Name);
|
|
||||||
// results.Add(fileData.File.Name);
|
|
||||||
// //count = Interlocked.Increment(ref count);
|
|
||||||
//
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// updateEvent?.Invoke(this, new Tuple<string, int>(fileData.File.Name, dataToProcess.Count));
|
|
||||||
// }
|
|
||||||
// catch (Exception e)
|
|
||||||
// {
|
|
||||||
// logger.LogError(e, "Error in reporting update");
|
|
||||||
// //Console.WriteLine(e);
|
|
||||||
// throw;
|
|
||||||
// }
|
|
||||||
// finally
|
|
||||||
// {
|
|
||||||
// // Disposing of the creator
|
|
||||||
// imgCreator = null;
|
|
||||||
// }
|
|
||||||
// }, maxDegreeOfParallelism: threads, false, cancellationToken);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// var asdf = SplitList(dataToProcess.ToList(), options.ChunksSize).ToList();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// foreach (var sdaf in asdf)
|
|
||||||
// {
|
|
||||||
// await sdaf.ParallelForEachAsync(async fileData =>
|
|
||||||
// {
|
|
||||||
// var imgCreator = new ImageCreatorSharp(fileData.File, fileData.Directory);
|
|
||||||
// await imgCreator.CreaImmagineThread(fileData.File.Name);
|
|
||||||
// // await new ImageCreatorSharp(fileData.File, fileData.Directory).CreaImmagineThread(
|
|
||||||
// // fileData.File.Name);
|
|
||||||
// results.Add(fileData.File.Name);
|
|
||||||
// //count = Interlocked.Increment(ref count);
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// updateEvent?.Invoke(this,
|
|
||||||
// new Tuple<string, int>(fileData.File.Name, dataToProcess.Count));
|
|
||||||
// }
|
|
||||||
// catch (Exception e)
|
|
||||||
// {
|
|
||||||
// logger.LogError("Error in reporting update");
|
|
||||||
// //Console.WriteLine(e);
|
|
||||||
// throw;
|
|
||||||
// }
|
|
||||||
// finally
|
|
||||||
// {
|
|
||||||
// imgCreator = null;
|
|
||||||
// }
|
|
||||||
// }, maxDegreeOfParallelism: threads, false, cancellationToken);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static IEnumerable<List<T>> SplitList<T>(List<T> bigList, int nSize = 3)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bigList.Count; i += nSize)
|
for (int i = 0; i < bigList.Count; i += nSize)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
{
|
{
|
||||||
public async Task CreaImmagineThread(ImageState imgState, Image logo)
|
public async Task CreaImmagineThread(ImageState imgState, Image logo)
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
|
|
@ -56,14 +55,8 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
SalvaFoto(imgOutputBig, imgState, thisFormat);
|
SalvaFoto(imgOutputBig, imgState, thisFormat);
|
||||||
});
|
});
|
||||||
|
|
||||||
// g.Dispose()
|
|
||||||
|
|
||||||
//GC.Collect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _picSettings.mainForm.stepProgressBar()
|
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var e = ex.Demystify();
|
var e = ex.Demystify();
|
||||||
|
|
@ -80,7 +73,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
var found = img.Metadata?.ExifProfile?.TryGetValue(ExifTag.Orientation, out rotation) ?? false;
|
var found = img.Metadata?.ExifProfile?.TryGetValue(ExifTag.Orientation, out rotation) ?? false;
|
||||||
|
|
||||||
if (found )
|
if (found)
|
||||||
{
|
{
|
||||||
var intOrientation = rotation.Value.ToInt32();
|
var intOrientation = rotation.Value.ToInt32();
|
||||||
imgState.Orientation = (Orientations)intOrientation;
|
imgState.Orientation = (Orientations)intOrientation;
|
||||||
|
|
@ -90,7 +83,8 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
var creationFound = img.Metadata?.ExifProfile?.TryGetValue(ExifTag.DateTimeOriginal, out date) ?? false;
|
var creationFound = img.Metadata?.ExifProfile?.TryGetValue(ExifTag.DateTimeOriginal, out date) ?? false;
|
||||||
if (creationFound)
|
if (creationFound)
|
||||||
{
|
{
|
||||||
var succ = DateTime.TryParseExact(date.Value, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out var crDate);
|
var succ = DateTime.TryParseExact(date.Value, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture,
|
||||||
|
DateTimeStyles.None, out var crDate);
|
||||||
if (succ)
|
if (succ)
|
||||||
{
|
{
|
||||||
imgState.CreationDate = crDate;
|
imgState.CreationDate = crDate;
|
||||||
|
|
@ -111,27 +105,21 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
imgState.FotoRuotaADestra = false;
|
imgState.FotoRuotaADestra = false;
|
||||||
imgState.FotoRuotaASinistra = false;
|
imgState.FotoRuotaASinistra = false;
|
||||||
|
|
||||||
if (picSettings.UsaRotazioneAutomatica == true)
|
if (picSettings.UsaRotazioneAutomatica && g.PropertyIdList.Length > 0)
|
||||||
{
|
{
|
||||||
if (g.PropertyIdList.Length > 0)
|
switch (imgState.Orientation)
|
||||||
{
|
{
|
||||||
//ExifReader DatiExif = new ExifReader((Bitmap)g);
|
case Orientations.BottomLeft:
|
||||||
|
case Orientations.BottomRight:
|
||||||
switch (imgState.Orientation /*DatiExif.Orientation*/)
|
case Orientations.LeftTop:
|
||||||
{
|
case Orientations.LftBottom:
|
||||||
case Orientations.BottomLeft:
|
imgState.FotoRuotaASinistra = true;
|
||||||
case Orientations.BottomRight:
|
break;
|
||||||
case Orientations.LeftTop:
|
case Orientations.RightBottom:
|
||||||
case Orientations.LftBottom:
|
case Orientations.RightTop:
|
||||||
imgState.FotoRuotaASinistra = true;
|
case Orientations.TopLeft:
|
||||||
break;
|
case Orientations.TopRight:
|
||||||
case Orientations.RightBottom:
|
break;
|
||||||
case Orientations.RightTop:
|
|
||||||
case Orientations.TopLeft:
|
|
||||||
case Orientations.TopRight:
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,7 +137,9 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
/// ''' <remarks></remarks>
|
/// ''' <remarks></remarks>
|
||||||
private void ImpostaTestoExtra(Image g, ImageState imgState)
|
private void ImpostaTestoExtra(Image g, ImageState imgState)
|
||||||
{
|
{
|
||||||
if (picSettings.UsaOrarioTestoApplicare | picSettings.UsaTempoGaraTestoApplicare | picSettings.UsaOrarioMiniatura | picSettings.TestoMin | picSettings.AggTempoGaraMin | picSettings.AggNumTempMin)
|
if (picSettings.UsaOrarioTestoApplicare | picSettings.UsaTempoGaraTestoApplicare |
|
||||||
|
picSettings.UsaOrarioMiniatura | picSettings.TestoMin | picSettings.AggTempoGaraMin |
|
||||||
|
picSettings.AggNumTempMin)
|
||||||
{
|
{
|
||||||
if (g.PropertyIdList.Length <= 0) return;
|
if (g.PropertyIdList.Length <= 0) return;
|
||||||
//ExifReader DatiExif = new ExifReader((Bitmap)g);
|
//ExifReader DatiExif = new ExifReader((Bitmap)g);
|
||||||
|
|
@ -170,7 +160,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
if (picSettings.UsaTempoGaraTestoApplicare != true) return;
|
if (picSettings.UsaTempoGaraTestoApplicare != true) return;
|
||||||
var diff = imgState.DataFoto - imgState.DataPartenzaI;
|
var diff = imgState.DataFoto - imgState.DataPartenzaI;
|
||||||
//var diffA = diff.TotalSeconds * 10000000;
|
//var diffA = diff.TotalSeconds * 10000000;
|
||||||
|
|
||||||
// var orario = new TimeSpan(0, Math.Abs(diff.Hours), Math.Abs(diff.Minutes), (int)diffA);
|
// var orario = new TimeSpan(0, Math.Abs(diff.Hours), Math.Abs(diff.Minutes), (int)diffA);
|
||||||
imgState.TestoFirma += $" {imgState.TestoOrario}{diff.Hours:00}:{diff.Minutes:00}:{diff.Seconds:00}";
|
imgState.TestoFirma += $" {imgState.TestoOrario}{diff.Hours:00}:{diff.Minutes:00}:{diff.Seconds:00}";
|
||||||
imgState.TestoFirmaV += $" {imgState.TestoOrario}{diff.Hours:00}:{diff.Minutes:00}:{diff.Seconds:00}";
|
imgState.TestoFirmaV += $" {imgState.TestoOrario}{diff.Hours:00}:{diff.Minutes:00}:{diff.Seconds:00}";
|
||||||
|
|
@ -209,7 +199,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
imgState.NomeFileBig = imgState.WorkFile.Name;
|
imgState.NomeFileBig = imgState.WorkFile.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepareThumbnailSize(Image g, ImageState imgState)
|
private void PrepareThumbnailSize(Image g, ImageState imgState)
|
||||||
{
|
{
|
||||||
if (g.Width > g.Height)
|
if (g.Width > g.Height)
|
||||||
{
|
{
|
||||||
|
|
@ -225,209 +215,403 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreaMiniature(Image g, ImageState imgState, Bitmap imgOutputBig, ImageFormat thisFormat)
|
// private void CreaMiniature(Image g, ImageState imgState, Bitmap imgOutputBig, ImageFormat thisFormat)
|
||||||
|
// {
|
||||||
|
// if (!picSettings.CreaMiniature || picSettings.AggiungiScritteMiniature)
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// if (picSettings.TestoMin)
|
||||||
|
// imgState.TestoFirmaPiccola = imgState.NomeFileBig;
|
||||||
|
// else if (picSettings.AggNumTempMin)
|
||||||
|
// imgState.TestoFirmaPiccola = imgState.NomeFileBig + " ";
|
||||||
|
//
|
||||||
|
// Font crFont1 = null;
|
||||||
|
// Font crFont2 = null;
|
||||||
|
// var crSize1 = new SizeF();
|
||||||
|
// var crSize2 = new SizeF();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione,
|
||||||
|
// StringComparison.OrdinalIgnoreCase))
|
||||||
|
// imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) +
|
||||||
|
// picSettings.Codice +
|
||||||
|
// imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
||||||
|
//
|
||||||
|
// if (picSettings.UsaOrarioMiniatura | picSettings.TestoMin | picSettings.AggTempoGaraMin |
|
||||||
|
// picSettings.AggNumTempMin)
|
||||||
|
// {
|
||||||
|
// if (imgState.TestoFirmaPiccola.Length > 0)
|
||||||
|
// {
|
||||||
|
// using var imgOutputSmall = (Bitmap)imgOutputBig.Clone();
|
||||||
|
// using var grPhoto1 = Graphics.FromImage(imgOutputSmall);
|
||||||
|
// grPhoto1.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
//
|
||||||
|
// // quick fix
|
||||||
|
// imgState.DimensioneStandardMiniatura = 50;
|
||||||
|
// if (picSettings.Grassetto == true)
|
||||||
|
// {
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura,
|
||||||
|
// FontStyle.Bold);
|
||||||
|
// crFont2 = new Font(picSettings.IlFont, imgState.DimensioneStandard, FontStyle.Bold);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura);
|
||||||
|
// crFont2 = new Font(picSettings.IlFont, imgState.DimensioneStandard);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// crSize1 = grPhoto1.MeasureString(imgState.TestoFirmaPiccola, crFont1);
|
||||||
|
// crSize2 = grPhoto1.MeasureString(imgState.TestoFirma, crFont1);
|
||||||
|
// var larghezzaStandard1 = System.Convert.ToInt32(crSize1.Width);
|
||||||
|
//
|
||||||
|
// if (crSize1.Width > System.Convert.ToSingle(g.Width))
|
||||||
|
// {
|
||||||
|
// int Conta = imgState.DimensioneStandardMiniatura;
|
||||||
|
// do
|
||||||
|
// {
|
||||||
|
// if (Conta > 20)
|
||||||
|
// Conta -= 5;
|
||||||
|
// else
|
||||||
|
// Conta -= 1;
|
||||||
|
// if (picSettings.Grassetto == true)
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, Conta, FontStyle.Bold);
|
||||||
|
// else
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, Conta);
|
||||||
|
// crSize1 = grPhoto1.MeasureString(imgState.TestoFirmaPiccola, crFont1);
|
||||||
|
// if (crSize1.Width < System.Convert.ToSingle(g.Width))
|
||||||
|
// {
|
||||||
|
// larghezzaStandard1 = System.Convert.ToInt32(crSize1.Width);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (Conta <= 5)
|
||||||
|
// break;
|
||||||
|
// } while (true);
|
||||||
|
//
|
||||||
|
// imgState.DimensioneStandardMiniatura = Conta;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// switch (picSettings.Posizione.ToUpper())
|
||||||
|
// {
|
||||||
|
// case "ALTO":
|
||||||
|
// {
|
||||||
|
// imgState.YPosFromBottom1 = (picSettings.Margine);
|
||||||
|
// imgState.YPosFromBottom4 = (picSettings.MargVert);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// case "BASSO":
|
||||||
|
// {
|
||||||
|
// imgState.YPosFromBottom1 = System.Convert.ToSingle((g.Height - crSize1.Height -
|
||||||
|
// (g.Height * picSettings.Margine /
|
||||||
|
// (double)100)));
|
||||||
|
// imgState.YPosFromBottom4 = System.Convert.ToSingle((g.Height - crSize1.Height -
|
||||||
|
// (g.Height * picSettings.MargVert /
|
||||||
|
// (double)100)));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// float xCenterOfImg1 = 0;
|
||||||
|
//
|
||||||
|
// using StringFormat strFormat1 = new StringFormat();
|
||||||
|
// switch (picSettings.Allineamento.ToUpper())
|
||||||
|
// {
|
||||||
|
// case "SINISTRA":
|
||||||
|
// {
|
||||||
|
// xCenterOfImg1 =
|
||||||
|
// System.Convert.ToSingle((picSettings.Margine + (larghezzaStandard1 / (double)2)));
|
||||||
|
//
|
||||||
|
// if ((larghezzaStandard1 / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
||||||
|
// xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// case "CENTRO":
|
||||||
|
// {
|
||||||
|
// xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// case "DESTRA":
|
||||||
|
// {
|
||||||
|
// xCenterOfImg1 = System.Convert.ToSingle((g.Width - picSettings.Margine -
|
||||||
|
// (larghezzaStandard1 / (double)2)));
|
||||||
|
//
|
||||||
|
// if ((larghezzaStandard1 / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
||||||
|
// xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// strFormat1.Alignment = StringAlignment.Center;
|
||||||
|
//
|
||||||
|
// using var semiTransBrush21 = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, 0, 0, 0));
|
||||||
|
// using var semiTransBrush1 =
|
||||||
|
// new SolidBrush(Color.FromArgb(imgState.AlphaScelta, picSettings.FontColoreRGB));
|
||||||
|
//
|
||||||
|
// // quick fix
|
||||||
|
// imgState.DimensioneStandardMiniatura = picSettings.DimMin;
|
||||||
|
//
|
||||||
|
// if (picSettings.Grassetto == true)
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura,
|
||||||
|
// FontStyle.Bold);
|
||||||
|
// else
|
||||||
|
// crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura);
|
||||||
|
//
|
||||||
|
// if (picSettings.TestoMin)
|
||||||
|
// {
|
||||||
|
// grPhoto1.DrawString(imgState.NomeFileBig, crFont1, semiTransBrush21,
|
||||||
|
// new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
||||||
|
// grPhoto1.DrawString(imgState.NomeFileBig, crFont1, semiTransBrush1,
|
||||||
|
// new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
||||||
|
// }
|
||||||
|
// else if (picSettings.AggTempoGaraMin & picSettings.UsaTempoGaraTestoApplicare)
|
||||||
|
// {
|
||||||
|
// var diff = imgState.DataPartenzaI - imgState.DataFoto;
|
||||||
|
// var diffA = diff.TotalSeconds * 10000000;
|
||||||
|
//
|
||||||
|
// var orario =
|
||||||
|
// new TimeSpan(0, 0,
|
||||||
|
// (int)diffA); /* new TimeSpan(DateTime.DateDiff(DateInterval.Second, dataPartenzaI, dataFoto) * 10000000);*/
|
||||||
|
// string tempstr = "";
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// tempstr += Environment.NewLine + imgState.TestoOrario + orario.Hours.ToString("00") + ":" +
|
||||||
|
// orario.Minutes.ToString("00") + ":" + orario.Seconds.ToString("00");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21,
|
||||||
|
// new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
||||||
|
// grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1,
|
||||||
|
// new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
||||||
|
// }
|
||||||
|
// else if (picSettings.AggNumTempMin)
|
||||||
|
// {
|
||||||
|
// var diff = imgState.DataPartenzaI - imgState.DataFoto;
|
||||||
|
// var diffA = diff.TotalSeconds * 10000000;
|
||||||
|
// TimeSpan Orario = new TimeSpan(0, 0, (int)diffA);
|
||||||
|
// string tempstr = "";
|
||||||
|
// tempstr += imgState.NomeFileBig;
|
||||||
|
//
|
||||||
|
// tempstr += Environment.NewLine + imgState.TestoOrario + Orario.Hours.ToString("00") + ":" +
|
||||||
|
// Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00");
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21,
|
||||||
|
// new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
||||||
|
// grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1,
|
||||||
|
// new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// grPhoto1.DrawString(imgState.TestoFirmaPiccola, crFont1, semiTransBrush21,
|
||||||
|
// new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
||||||
|
// grPhoto1.DrawString(imgState.TestoFirmaPiccola, crFont1, semiTransBrush1,
|
||||||
|
// new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Salva la miniatura
|
||||||
|
// //using (var g22 = Image.FromHbitmap(imgOutputSmall))
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// using var imgOutputSmall2 = new Bitmap(imgOutputSmall, imgState.ThumbSizeSmall.Width,
|
||||||
|
// imgState.ThumbSizeSmall.Height);
|
||||||
|
// imgOutputSmall2.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall),
|
||||||
|
// thisFormat);
|
||||||
|
//
|
||||||
|
// //imgOutputSmall2.Dispose();
|
||||||
|
//
|
||||||
|
// //imgOutputSmall.Dispose();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //File.Delete(Path.Combine(DestDir.FullName, "Temp_" + nomeFileSmall));
|
||||||
|
// //FileSystem.Kill();
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// using var imgOutputSmall = new Bitmap(g, imgState.ThumbSizeSmall.Width,
|
||||||
|
// imgState.ThumbSizeSmall.Height);
|
||||||
|
// imgOutputSmall.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall),
|
||||||
|
// thisFormat);
|
||||||
|
// //imgOutputSmall.Dispose();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// using var imgOutputSmall =
|
||||||
|
// new Bitmap(g, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
||||||
|
// imgOutputSmall.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), thisFormat);
|
||||||
|
// //imgOutputSmall.Dispose();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// crFont1?.Dispose();
|
||||||
|
// crFont2?.Dispose();
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void CreaMiniature(Image sourceImage, ImageState imgState, Bitmap imgOutputBig, ImageFormat format)
|
||||||
|
{
|
||||||
|
if (!picSettings.CreaMiniature || picSettings.AggiungiScritteMiniature)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PrepareSignatureText(imgState);
|
||||||
|
|
||||||
|
if (IsSameDirectory(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione))
|
||||||
|
UpdateFileNameWithCode(imgState);
|
||||||
|
|
||||||
|
if (ShouldRenderText())
|
||||||
|
CreateMiniatureWithText(sourceImage, imgState, imgOutputBig, format);
|
||||||
|
else
|
||||||
|
CreateSimpleThumbnail(sourceImage, imgState, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PrepareSignatureText(ImageState imgState)
|
||||||
{
|
{
|
||||||
if (picSettings.TestoMin)
|
if (picSettings.TestoMin)
|
||||||
imgState.TestoFirmaPiccola = imgState.NomeFileBig;
|
imgState.TestoFirmaPiccola = imgState.NomeFileBig;
|
||||||
else if (picSettings.AggNumTempMin)
|
else if (picSettings.AggNumTempMin)
|
||||||
imgState.TestoFirmaPiccola = imgState.NomeFileBig + " ";
|
imgState.TestoFirmaPiccola = imgState.NomeFileBig + " ";
|
||||||
// Dim yPosFromBottom4 As Single
|
}
|
||||||
|
|
||||||
Font crFont1 = null/* TODO Change to default(_) if this is not a reference type */;
|
private bool IsSameDirectory(string dir1, string dir2) =>
|
||||||
Font crFont2 = null/* TODO Change to default(_) if this is not a reference type */;
|
string.Equals(dir1, dir2, StringComparison.OrdinalIgnoreCase);
|
||||||
var crSize1 = new SizeF();
|
|
||||||
var crSize2 = new SizeF();
|
|
||||||
|
|
||||||
if (picSettings.CreaMiniature == true)
|
private void UpdateFileNameWithCode(ImageState imgState)
|
||||||
|
{
|
||||||
|
var name = imgState.NomeFileSmall;
|
||||||
|
imgState.NomeFileSmall = name[..^4] + picSettings.Codice + name[^4..];
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ShouldRenderText() =>
|
||||||
|
picSettings.UsaOrarioMiniatura || picSettings.TestoMin || picSettings.AggTempoGaraMin ||
|
||||||
|
picSettings.AggNumTempMin;
|
||||||
|
|
||||||
|
private void CreateSimpleThumbnail(Image image, ImageState imgState, ImageFormat format)
|
||||||
|
{
|
||||||
|
using var thumbnail = new Bitmap(image, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
||||||
|
thumbnail.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateMiniatureWithText(Image image, ImageState imgState, Bitmap sourceBitmap, ImageFormat format)
|
||||||
|
{
|
||||||
|
if (imgState.TestoFirmaPiccola.Length == 0)
|
||||||
{
|
{
|
||||||
if (picSettings.AggiungiScritteMiniature == false)
|
CreateSimpleThumbnail(image, imgState, format);
|
||||||
{
|
return;
|
||||||
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
|
|
||||||
imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) + picSettings.Codice + imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
|
||||||
if (picSettings.UsaOrarioMiniatura | picSettings.TestoMin | picSettings.AggTempoGaraMin | picSettings.AggNumTempMin)
|
|
||||||
{
|
|
||||||
if (imgState.TestoFirmaPiccola.Length > 0)
|
|
||||||
{
|
|
||||||
using var imgOutputSmall = (Bitmap)imgOutputBig.Clone();
|
|
||||||
using var grPhoto1 = Graphics.FromImage(imgOutputSmall);
|
|
||||||
grPhoto1.SmoothingMode = SmoothingMode.AntiAlias;
|
|
||||||
|
|
||||||
// quick fix
|
|
||||||
imgState.DimensioneStandardMiniatura = 50;
|
|
||||||
if (picSettings.Grassetto == true)
|
|
||||||
{
|
|
||||||
crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura, FontStyle.Bold);
|
|
||||||
crFont2 = new Font(picSettings.IlFont, imgState.DimensioneStandard, FontStyle.Bold);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura);
|
|
||||||
crFont2 = new Font(picSettings.IlFont, imgState.DimensioneStandard);
|
|
||||||
}
|
|
||||||
|
|
||||||
crSize1 = grPhoto1.MeasureString(imgState.TestoFirmaPiccola, crFont1);
|
|
||||||
crSize2 = grPhoto1.MeasureString(imgState.TestoFirma, crFont1);
|
|
||||||
var larghezzaStandard1 = System.Convert.ToInt32(crSize1.Width);
|
|
||||||
|
|
||||||
if (crSize1.Width > System.Convert.ToSingle(g.Width))
|
|
||||||
{
|
|
||||||
int Conta = imgState.DimensioneStandardMiniatura;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (Conta > 20)
|
|
||||||
Conta -= 5;
|
|
||||||
else
|
|
||||||
Conta -= 1;
|
|
||||||
if (picSettings.Grassetto == true)
|
|
||||||
crFont1 = new Font(picSettings.IlFont, Conta, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
crFont1 = new Font(picSettings.IlFont, Conta);
|
|
||||||
crSize1 = grPhoto1.MeasureString(imgState.TestoFirmaPiccola, crFont1);
|
|
||||||
if (crSize1.Width < System.Convert.ToSingle(g.Width))
|
|
||||||
{
|
|
||||||
larghezzaStandard1 = System.Convert.ToInt32(crSize1.Width);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Conta <= 5)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
while (true);
|
|
||||||
imgState.DimensioneStandardMiniatura = Conta;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (picSettings.Posizione.ToUpper())
|
|
||||||
{
|
|
||||||
case "ALTO":
|
|
||||||
{
|
|
||||||
imgState.YPosFromBottom1 = (picSettings.Margine);
|
|
||||||
imgState.YPosFromBottom4 = (picSettings.MargVert);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "BASSO":
|
|
||||||
{
|
|
||||||
imgState.YPosFromBottom1 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * picSettings.Margine / (double)100)));
|
|
||||||
imgState.YPosFromBottom4 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * picSettings.MargVert / (double)100)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float xCenterOfImg1 = 0;
|
|
||||||
|
|
||||||
using StringFormat strFormat1 = new StringFormat();
|
|
||||||
switch (picSettings.Allineamento.ToUpper())
|
|
||||||
{
|
|
||||||
case "SINISTRA":
|
|
||||||
{
|
|
||||||
xCenterOfImg1 = System.Convert.ToSingle((picSettings.Margine + (larghezzaStandard1 / (double)2)));
|
|
||||||
|
|
||||||
if ((larghezzaStandard1 / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
|
||||||
xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "CENTRO":
|
|
||||||
{
|
|
||||||
xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case "DESTRA":
|
|
||||||
{
|
|
||||||
xCenterOfImg1 = System.Convert.ToSingle((g.Width - picSettings.Margine - (larghezzaStandard1 / (double)2)));
|
|
||||||
|
|
||||||
if ((larghezzaStandard1 / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
|
||||||
xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strFormat1.Alignment = StringAlignment.Center;
|
|
||||||
|
|
||||||
using var semiTransBrush21 = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, 0, 0, 0));
|
|
||||||
using var semiTransBrush1 = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, picSettings.FontColoreRGB));
|
|
||||||
|
|
||||||
// quick fix
|
|
||||||
imgState.DimensioneStandardMiniatura = picSettings.DimMin;
|
|
||||||
|
|
||||||
if (picSettings.Grassetto == true)
|
|
||||||
crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura, FontStyle.Bold);
|
|
||||||
else
|
|
||||||
crFont1 = new Font(picSettings.IlFont, imgState.DimensioneStandardMiniatura);
|
|
||||||
// asdgadfhdfhjgfsjgfjygfdhsdafa
|
|
||||||
if (picSettings.TestoMin)
|
|
||||||
{
|
|
||||||
grPhoto1.DrawString(imgState.NomeFileBig, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
|
||||||
grPhoto1.DrawString(imgState.NomeFileBig, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
|
||||||
}
|
|
||||||
else if (picSettings.AggTempoGaraMin & picSettings.UsaTempoGaraTestoApplicare)
|
|
||||||
{
|
|
||||||
var diff = imgState.DataPartenzaI - imgState.DataFoto;
|
|
||||||
var diffA = diff.TotalSeconds * 10000000;
|
|
||||||
|
|
||||||
var orario = new TimeSpan(0, 0, (int)diffA);/* new TimeSpan(DateTime.DateDiff(DateInterval.Second, dataPartenzaI, dataFoto) * 10000000);*/
|
|
||||||
string tempstr = "";
|
|
||||||
|
|
||||||
|
|
||||||
tempstr += Environment.NewLine + imgState.TestoOrario + orario.Hours.ToString("00") + ":" + orario.Minutes.ToString("00") + ":" + orario.Seconds.ToString("00");
|
|
||||||
|
|
||||||
|
|
||||||
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
|
||||||
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
|
||||||
}
|
|
||||||
else if (picSettings.AggNumTempMin)
|
|
||||||
{
|
|
||||||
var diff = imgState.DataPartenzaI - imgState.DataFoto;
|
|
||||||
var diffA = diff.TotalSeconds * 10000000;
|
|
||||||
TimeSpan Orario = new TimeSpan(0, 0, (int)diffA);
|
|
||||||
string tempstr = "";
|
|
||||||
tempstr += imgState.NomeFileBig;
|
|
||||||
|
|
||||||
tempstr += Environment.NewLine + imgState.TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00");
|
|
||||||
|
|
||||||
|
|
||||||
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
|
||||||
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
grPhoto1.DrawString(imgState.TestoFirmaPiccola, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, imgState.YPosFromBottom1 + 1), strFormat1);
|
|
||||||
grPhoto1.DrawString(imgState.TestoFirmaPiccola, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, imgState.YPosFromBottom1), strFormat1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Salva la miniatura
|
|
||||||
//using (var g22 = Image.FromHbitmap(imgOutputSmall))
|
|
||||||
|
|
||||||
|
|
||||||
using var imgOutputSmall2 = new Bitmap(imgOutputSmall, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
|
||||||
imgOutputSmall2.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), thisFormat);
|
|
||||||
|
|
||||||
//imgOutputSmall2.Dispose();
|
|
||||||
|
|
||||||
//imgOutputSmall.Dispose();
|
|
||||||
|
|
||||||
|
|
||||||
//File.Delete(Path.Combine(DestDir.FullName, "Temp_" + nomeFileSmall));
|
|
||||||
//FileSystem.Kill();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
using var imgOutputSmall = new Bitmap(g, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
|
||||||
imgOutputSmall.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), thisFormat);
|
|
||||||
//imgOutputSmall.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
using var imgOutputSmall = new Bitmap(g, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
|
||||||
imgOutputSmall.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), thisFormat);
|
|
||||||
//imgOutputSmall.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crFont1?.Dispose();
|
using var imgOutputSmall = (Bitmap)sourceBitmap.Clone();
|
||||||
crFont2?.Dispose();
|
using var graphics = Graphics.FromImage(imgOutputSmall);
|
||||||
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
|
||||||
|
imgState.DimensioneStandardMiniatura = 50;
|
||||||
|
|
||||||
|
using var font1 = CreateFont(picSettings.IlFont, imgState.DimensioneStandardMiniatura, picSettings.Grassetto);
|
||||||
|
var textSize = graphics.MeasureString(imgState.TestoFirmaPiccola, font1);
|
||||||
|
|
||||||
|
AdjustFontToFitWidth(graphics, image.Width, imgState, ref textSize);
|
||||||
|
|
||||||
|
SetVerticalPosition(image.Height, textSize.Height, imgState);
|
||||||
|
|
||||||
|
float xCenter = CalculateHorizontalAlignment(image.Width, textSize.Width);
|
||||||
|
using var stringFormat = new StringFormat();
|
||||||
|
stringFormat.Alignment = StringAlignment.Center;
|
||||||
|
|
||||||
|
using var shadowBrush = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, 0, 0, 0));
|
||||||
|
using var textBrush = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, picSettings.FontColoreRGB));
|
||||||
|
|
||||||
|
imgState.DimensioneStandardMiniatura = picSettings.DimMin;
|
||||||
|
|
||||||
|
using var finalFont =
|
||||||
|
CreateFont(picSettings.IlFont, imgState.DimensioneStandardMiniatura, picSettings.Grassetto);
|
||||||
|
DrawText(graphics, imgState, xCenter, stringFormat, shadowBrush, textBrush, finalFont);
|
||||||
|
|
||||||
|
using var finalThumb =
|
||||||
|
new Bitmap(imgOutputSmall, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
||||||
|
finalThumb.Save(Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Font CreateFont(string fontName, int size, bool bold) =>
|
||||||
|
new Font(fontName, size, bold ? FontStyle.Bold : FontStyle.Regular);
|
||||||
|
|
||||||
|
private void AdjustFontToFitWidth(Graphics g, int maxWidth, ImageState imgState, ref SizeF size)
|
||||||
|
{
|
||||||
|
int currentSize = imgState.DimensioneStandardMiniatura;
|
||||||
|
|
||||||
|
while (size.Width > maxWidth && currentSize > 5)
|
||||||
|
{
|
||||||
|
currentSize = (currentSize > 20) ? currentSize - 5 : currentSize - 1;
|
||||||
|
using var tempFont = CreateFont(picSettings.IlFont, currentSize, picSettings.Grassetto);
|
||||||
|
size = g.MeasureString(imgState.TestoFirmaPiccola, tempFont);
|
||||||
|
//tempFont.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
imgState.DimensioneStandardMiniatura = currentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetVerticalPosition(int imgHeight, float textHeight, ImageState imgState)
|
||||||
|
{
|
||||||
|
switch (picSettings.Posizione.ToUpper())
|
||||||
|
{
|
||||||
|
case "ALTO":
|
||||||
|
imgState.YPosFromBottom1 = picSettings.Margine;
|
||||||
|
imgState.YPosFromBottom4 = picSettings.MargVert;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "BASSO":
|
||||||
|
imgState.YPosFromBottom1 = (float)(imgHeight - textHeight - (imgHeight * picSettings.Margine / 100.0));
|
||||||
|
imgState.YPosFromBottom4 = (float)(imgHeight - textHeight - (imgHeight * picSettings.MargVert / 100.0));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float CalculateHorizontalAlignment(int imgWidth, float textWidth)
|
||||||
|
{
|
||||||
|
double halfWidth = textWidth / 2.0;
|
||||||
|
|
||||||
|
return picSettings.Allineamento.ToUpper() switch
|
||||||
|
{
|
||||||
|
"SINISTRA" => (float)Math.Min(picSettings.Margine + halfWidth, imgWidth / 2.0),
|
||||||
|
"DESTRA" => (float)Math.Max(imgWidth - picSettings.Margine - halfWidth, imgWidth / 2.0),
|
||||||
|
_ => imgWidth / 2.0f, // CENTRO or default
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawText(Graphics g, ImageState imgState, float x, StringFormat format,
|
||||||
|
Brush shadowBrush, Brush textBrush, Font font)
|
||||||
|
{
|
||||||
|
string content = imgState.TestoFirmaPiccola;
|
||||||
|
|
||||||
|
if (picSettings.TestoMin)
|
||||||
|
{
|
||||||
|
content = imgState.NomeFileBig;
|
||||||
|
}
|
||||||
|
else if (picSettings.AggTempoGaraMin && picSettings.UsaTempoGaraTestoApplicare)
|
||||||
|
{
|
||||||
|
content = FormatTimeText(imgState, includeFileName: false);
|
||||||
|
}
|
||||||
|
else if (picSettings.AggNumTempMin)
|
||||||
|
{
|
||||||
|
content = FormatTimeText(imgState, includeFileName: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
var offset = new PointF(x + 1, imgState.YPosFromBottom1 + 1);
|
||||||
|
var actual = new PointF(x, imgState.YPosFromBottom1);
|
||||||
|
|
||||||
|
g.DrawString(content, font, shadowBrush, offset, format);
|
||||||
|
g.DrawString(content, font, textBrush, actual, format);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FormatTimeText(ImageState imgState, bool includeFileName)
|
||||||
|
{
|
||||||
|
var diff = imgState.DataPartenzaI - imgState.DataFoto;
|
||||||
|
var ticks = (long)(diff.TotalSeconds * 10000000);
|
||||||
|
var time = new TimeSpan(ticks);
|
||||||
|
|
||||||
|
var formatted = $"{imgState.TestoOrario}{time:hh\\:mm\\:ss}";
|
||||||
|
return includeFileName
|
||||||
|
? $"{imgState.NomeFileBig}{Environment.NewLine}{formatted}"
|
||||||
|
: Environment.NewLine + formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AggiungiTesto(Image g, ImageState imgState, Bitmap imgOutputBig)
|
private void AggiungiTesto(Image g, ImageState imgState, Bitmap imgOutputBig)
|
||||||
|
|
@ -435,7 +619,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
using var grPhoto = Graphics.FromImage(imgOutputBig);
|
using var grPhoto = Graphics.FromImage(imgOutputBig);
|
||||||
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
|
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
|
||||||
Font crFont = null/* TODO Change to default(_) if this is not a reference type */;
|
Font crFont = null /* TODO Change to default(_) if this is not a reference type */;
|
||||||
|
|
||||||
if (picSettings.Grassetto == true)
|
if (picSettings.Grassetto == true)
|
||||||
crFont = new Font(picSettings.IlFont, imgState.DimensioneStandard, FontStyle.Bold);
|
crFont = new Font(picSettings.IlFont, imgState.DimensioneStandard, FontStyle.Bold);
|
||||||
|
|
@ -466,11 +650,11 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
if (conta <= 5)
|
if (conta <= 5)
|
||||||
break;
|
break;
|
||||||
}
|
} while (true);
|
||||||
while (true);
|
|
||||||
imgState.DimensioneStandard = conta;
|
imgState.DimensioneStandard = conta;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (picSettings.Posizione.ToUpper())
|
switch (picSettings.Posizione.ToUpper())
|
||||||
{
|
{
|
||||||
case "ALTO":
|
case "ALTO":
|
||||||
|
|
@ -482,8 +666,12 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
case "BASSO":
|
case "BASSO":
|
||||||
{
|
{
|
||||||
imgState.YPosFromBottom = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * picSettings.Margine / (double)100)));
|
imgState.YPosFromBottom =
|
||||||
imgState.YPosFromBottom3 = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * picSettings.MargVert / (double)100)));
|
System.Convert.ToSingle((g.Height - crSize.Height -
|
||||||
|
(g.Height * picSettings.Margine / (double)100)));
|
||||||
|
imgState.YPosFromBottom3 =
|
||||||
|
System.Convert.ToSingle(
|
||||||
|
(g.Height - crSize.Height - (g.Height * picSettings.MargVert / (double)100)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -512,8 +700,10 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
|
|
||||||
case "DESTRA":
|
case "DESTRA":
|
||||||
{
|
{
|
||||||
xCenterOfImg = System.Convert.ToSingle((g.Width - picSettings.Margine - (larghezzaStandard / (double)2)));
|
xCenterOfImg =
|
||||||
xCenterOfImg3 = System.Convert.ToSingle((g.Width - picSettings.MargVert - (larghezzaStandard / (double)2)));
|
System.Convert.ToSingle((g.Width - picSettings.Margine - (larghezzaStandard / (double)2)));
|
||||||
|
xCenterOfImg3 =
|
||||||
|
System.Convert.ToSingle((g.Width - picSettings.MargVert - (larghezzaStandard / (double)2)));
|
||||||
if ((larghezzaStandard / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
if ((larghezzaStandard / (double)2) > (g.Width / (double)2) - picSettings.Margine)
|
||||||
xCenterOfImg = System.Convert.ToSingle((g.Width / (double)2));
|
xCenterOfImg = System.Convert.ToSingle((g.Width / (double)2));
|
||||||
if ((larghezzaStandard / (double)2) > (g.Width / (double)2) - picSettings.MargVert)
|
if ((larghezzaStandard / (double)2) > (g.Width / (double)2) - picSettings.MargVert)
|
||||||
|
|
@ -521,6 +711,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strFormat.Alignment = StringAlignment.Center;
|
strFormat.Alignment = StringAlignment.Center;
|
||||||
|
|
||||||
using var semiTransBrush2 = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, 0, 0, 0));
|
using var semiTransBrush2 = new SolidBrush(Color.FromArgb(imgState.AlphaScelta, 0, 0, 0));
|
||||||
|
|
@ -548,13 +739,17 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
//ExifReader DatiExif = new ExifReader((Bitmap)g);
|
//ExifReader DatiExif = new ExifReader((Bitmap)g);
|
||||||
imgState.DataFoto = imgState.CreationDate ?? DateTime.Now; //DatiExif.DateTimeOriginal;
|
imgState.DataFoto = imgState.CreationDate ?? DateTime.Now; //DatiExif.DateTimeOriginal;
|
||||||
|
|
||||||
grPhoto.DrawString((imgState.NomeFileBig + " " + imgState.DataFoto.ToShortDateString()), crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
grPhoto.DrawString((imgState.NomeFileBig + " " + imgState.DataFoto.ToShortDateString()), crFont,
|
||||||
grPhoto.DrawString((imgState.NomeFileBig + " " + imgState.DataFoto.ToShortDateString()), crFont, semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
||||||
|
grPhoto.DrawString((imgState.NomeFileBig + " " + imgState.DataFoto.ToShortDateString()), crFont,
|
||||||
|
semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grPhoto.DrawString(imgState.NomeFileBig, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
grPhoto.DrawString(imgState.NomeFileBig, crFont, semiTransBrush2,
|
||||||
grPhoto.DrawString(imgState.NomeFileBig, crFont, semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
||||||
|
grPhoto.DrawString(imgState.NomeFileBig, crFont, semiTransBrush,
|
||||||
|
new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -564,23 +759,31 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
{
|
{
|
||||||
if (picSettings.TestoMin == false)
|
if (picSettings.TestoMin == false)
|
||||||
{
|
{
|
||||||
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom3 + 1), strFormat);
|
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush2,
|
||||||
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom3), strFormat);
|
new PointF(xCenterOfImg + 1, imgState.YPosFromBottom3 + 1), strFormat);
|
||||||
|
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush,
|
||||||
|
new PointF(xCenterOfImg, imgState.YPosFromBottom3), strFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (picSettings.TestoMin == true)
|
if (picSettings.TestoMin == true)
|
||||||
{
|
{
|
||||||
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom4 + 1), strFormat);
|
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush2,
|
||||||
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom4), strFormat);
|
new PointF(xCenterOfImg + 1, imgState.YPosFromBottom4 + 1), strFormat);
|
||||||
|
grPhoto.DrawString(imgState.TestoFirmaV, crFont, semiTransBrush,
|
||||||
|
new PointF(xCenterOfImg, imgState.YPosFromBottom4), strFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grPhoto.DrawString(imgState.TestoFirma, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
grPhoto.DrawString(imgState.TestoFirma, crFont, semiTransBrush2,
|
||||||
grPhoto.DrawString(imgState.TestoFirma, crFont, semiTransBrush, new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
new PointF(xCenterOfImg + 1, imgState.YPosFromBottom + 1), strFormat);
|
||||||
|
grPhoto.DrawString(imgState.TestoFirma, crFont, semiTransBrush,
|
||||||
|
new PointF(xCenterOfImg, imgState.YPosFromBottom), strFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione,
|
||||||
|
StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
imgState.NomeFileBig2 = imgState.NomeFileBig;
|
imgState.NomeFileBig2 = imgState.NomeFileBig;
|
||||||
imgState.NomeFileBig = $"{imgState.NomeFileBig[..^4]}{picSettings.Codice}{imgState.NomeFileBig[^4..]}";
|
imgState.NomeFileBig = $"{imgState.NomeFileBig[..^4]}{picSettings.Codice}{imgState.NomeFileBig[^4..]}";
|
||||||
|
|
@ -614,7 +817,13 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
|
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
|
||||||
|
|
||||||
// * The second color manipulation is used to change the opacity by setting the 3rd row and 3rd column to 0.3f
|
// * The second color manipulation is used to change the opacity by setting the 3rd row and 3rd column to 0.3f
|
||||||
var colorMatrixElements = new[] { new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F }, new float[] { 0.0F, 1.0F, 0.0F, 0.0F, 0.0F }, new float[] { 0.0F, 0.0F, 1.0F, 0.0F, 0.0F }, new float[] { 0.0F, 0.0F, 0.0F, System.Convert.ToSingle(picSettings.LogoTrasparenza) / 100F, 0.0F }, new float[] { 0.0F, 0.0F, 0.0F, 0.0F, 1.0F } };
|
var colorMatrixElements = new[]
|
||||||
|
{
|
||||||
|
new float[] { 1.0F, 0.0F, 0.0F, 0.0F, 0.0F }, new float[] { 0.0F, 1.0F, 0.0F, 0.0F, 0.0F },
|
||||||
|
new float[] { 0.0F, 0.0F, 1.0F, 0.0F, 0.0F },
|
||||||
|
new float[] { 0.0F, 0.0F, 0.0F, System.Convert.ToSingle(picSettings.LogoTrasparenza) / 100F, 0.0F },
|
||||||
|
new float[] { 0.0F, 0.0F, 0.0F, 0.0F, 1.0F }
|
||||||
|
};
|
||||||
var wmColorMatrix = new ColorMatrix(colorMatrixElements);
|
var wmColorMatrix = new ColorMatrix(colorMatrixElements);
|
||||||
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
||||||
|
|
||||||
|
|
@ -622,11 +831,14 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
var fotoLogoW = picSettings.LogoLarghezza;
|
var fotoLogoW = picSettings.LogoLarghezza;
|
||||||
var fattoreAlt = logo.Height / (double)fotoLogoH;
|
var fattoreAlt = logo.Height / (double)fotoLogoH;
|
||||||
var fattoreLarg = logo.Width / (double)fotoLogoW;
|
var fattoreLarg = logo.Width / (double)fotoLogoW;
|
||||||
var nuovaSize = fattoreLarg > fattoreAlt ? NewthumbSize(logo.Width, logo.Height, fotoLogoW, "Larghezza") : NewthumbSize(logo.Width, logo.Height, fotoLogoH, "Altezza");
|
var nuovaSize = fattoreLarg > fattoreAlt
|
||||||
|
? NewthumbSize(logo.Width, logo.Height, fotoLogoW, "Larghezza")
|
||||||
|
: NewthumbSize(logo.Width, logo.Height, fotoLogoH, "Altezza");
|
||||||
|
|
||||||
var inPercentualeL = picSettings.LogoMargine.EndsWith('%');
|
var inPercentualeL = picSettings.LogoMargine.EndsWith('%');
|
||||||
var margineL = System.Convert.ToInt32(picSettings.LogoMargine);
|
var margineL = System.Convert.ToInt32(picSettings.LogoMargine);
|
||||||
var margineUsato = inPercentualeL ? System.Convert.ToInt32(imgOutputBig.Height * margineL / (double)100) : margineL;
|
var margineUsato =
|
||||||
|
inPercentualeL ? System.Convert.ToInt32(imgOutputBig.Height * margineL / (double)100) : margineL;
|
||||||
|
|
||||||
int xPosOfWm = 0;
|
int xPosOfWm = 0;
|
||||||
int yPosOfWm = 0;
|
int yPosOfWm = 0;
|
||||||
|
|
@ -651,6 +863,7 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (picSettings.LogoPosizioneV.ToUpper())
|
switch (picSettings.LogoPosizioneV.ToUpper())
|
||||||
{
|
{
|
||||||
case "ALTO":
|
case "ALTO":
|
||||||
|
|
@ -673,16 +886,16 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grWatermark.DrawImage(logo, new Rectangle(xPosOfWm, yPosOfWm, nuovaSize.Width, nuovaSize.Height), 0, 0, logo.Width, logo.Height, GraphicsUnit.Pixel, imageAttributes);
|
grWatermark.DrawImage(logo, new Rectangle(xPosOfWm, yPosOfWm, nuovaSize.Width, nuovaSize.Height), 0, 0,
|
||||||
|
logo.Width, logo.Height, GraphicsUnit.Pixel, imageAttributes);
|
||||||
//grWatermark.Dispose();
|
//grWatermark.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SalvaFoto(Bitmap imgOutputBig, ImageState imgState, ImageFormat thisFormat)
|
private void SalvaFoto(Bitmap imgOutputBig, ImageState imgState, ImageFormat thisFormat)
|
||||||
{
|
{
|
||||||
|
|
||||||
var fileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig);
|
var fileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileBig);
|
||||||
|
|
||||||
using var image1Stream = new MemoryStream();
|
using var image1Stream = new MemoryStream();
|
||||||
if (picSettings.FotoGrandeDimOrigina == false)
|
if (picSettings.FotoGrandeDimOrigina == false)
|
||||||
{
|
{
|
||||||
|
|
@ -697,10 +910,13 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
{
|
{
|
||||||
imgOutputBig.Save(image1Stream, thisFormat);
|
imgOutputBig.Save(image1Stream, thisFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
//imgOutputBig.Save(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig), thisFormat);
|
//imgOutputBig.Save(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig), thisFormat);
|
||||||
image1Stream.Seek(0, SeekOrigin.Begin);
|
image1Stream.Seek(0, SeekOrigin.Begin);
|
||||||
using var g2 = Image.FromStream(image1Stream);
|
using var g2 = Image.FromStream(image1Stream);
|
||||||
imgState.ThumbSizeBig = g2.Width > g2.Height ? NewthumbSize(g2.Width, g2.Height, picSettings.LarghezzaBig, "Larghezza") : NewthumbSize(g2.Width, g2.Height, picSettings.AltezzaBig, "Altezza");
|
imgState.ThumbSizeBig = g2.Width > g2.Height
|
||||||
|
? NewthumbSize(g2.Width, g2.Height, picSettings.LarghezzaBig, "Larghezza")
|
||||||
|
: NewthumbSize(g2.Width, g2.Height, picSettings.AltezzaBig, "Altezza");
|
||||||
using var imgOutputBig2 = new Bitmap(g2, imgState.ThumbSizeBig.Width, imgState.ThumbSizeBig.Height);
|
using var imgOutputBig2 = new Bitmap(g2, imgState.ThumbSizeBig.Width, imgState.ThumbSizeBig.Height);
|
||||||
|
|
||||||
if (!picSettings.OverwriteFiles && File.Exists(fileName))
|
if (!picSettings.OverwriteFiles && File.Exists(fileName))
|
||||||
|
|
@ -714,7 +930,6 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
else
|
else
|
||||||
imgOutputBig2.Save(fileName, thisFormat);
|
imgOutputBig2.Save(fileName, thisFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -730,19 +945,22 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
imgOutputBig.Save(fileName, thisFormat);
|
imgOutputBig.Save(fileName, thisFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image1Stream.Seek(0, SeekOrigin.Begin);
|
image1Stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
if (!picSettings.CreaMiniature) return;
|
if (!picSettings.CreaMiniature) return;
|
||||||
if (!picSettings.AggiungiScritteMiniature) return;
|
if (!picSettings.AggiungiScritteMiniature) return;
|
||||||
|
|
||||||
using var g1 = picSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
|
using var g1 = picSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
|
||||||
|
|
||||||
using var imgOutputSmall = new Bitmap(g1, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
using var imgOutputSmall = new Bitmap(g1, imgState.ThumbSizeSmall.Width, imgState.ThumbSizeSmall.Height);
|
||||||
|
|
||||||
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(picSettings.DirectorySorgente, picSettings.DirectoryDestinazione,
|
||||||
imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) + picSettings.Codice + imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
StringComparison.OrdinalIgnoreCase))
|
||||||
|
imgState.NomeFileSmall = imgState.NomeFileSmall.Substring(0, imgState.NomeFileSmall.Length - 4) +
|
||||||
|
picSettings.Codice +
|
||||||
|
imgState.NomeFileSmall.Substring(imgState.NomeFileSmall.Length - 4);
|
||||||
|
|
||||||
var tnFileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall);
|
var tnFileName = Path.Combine(imgState.DestDir.FullName, imgState.NomeFileSmall);
|
||||||
|
|
||||||
if (!picSettings.OverwriteFiles && File.Exists(tnFileName))
|
if (!picSettings.OverwriteFiles && File.Exists(tnFileName))
|
||||||
|
|
@ -784,19 +1002,20 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
imageToSave.Save(destinationStream, jgpEncoder, myEncoderParameters);
|
imageToSave.Save(destinationStream, jgpEncoder, myEncoderParameters);
|
||||||
//imageToSave.Dispose();
|
//imageToSave.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageCodecInfo GetEncoder(ImageFormat format)
|
private ImageCodecInfo GetEncoder(ImageFormat format)
|
||||||
{
|
{
|
||||||
var codecs = ImageCodecInfo.GetImageDecoders();
|
var codecs = ImageCodecInfo.GetImageDecoders();
|
||||||
|
|
||||||
foreach (var codec in codecs)
|
foreach (var codec in codecs)
|
||||||
{
|
{
|
||||||
if (codec.FormatID == format.Guid)
|
if (codec.FormatID == format.Guid)
|
||||||
return codec;
|
return codec;
|
||||||
}
|
}
|
||||||
return null/* TODO Change to default(_) if this is not a reference type */;
|
|
||||||
|
return null /* TODO Change to default(_) if this is not a reference type */;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ''' Calculate the Size of the New image
|
/// ''' Calculate the Size of the New image
|
||||||
/// ''' </summary>
|
/// ''' </summary>
|
||||||
|
|
@ -822,10 +1041,9 @@ public class ImageCreatorSharp(PicSettings picSettings, ILogger<ImageCreatorShar
|
||||||
else
|
else
|
||||||
tempMultiplier = maxPixel / (double)currentwidth;
|
tempMultiplier = maxPixel / (double)currentwidth;
|
||||||
|
|
||||||
var newSize = new Size(System.Convert.ToInt32(currentwidth * tempMultiplier), System.Convert.ToInt32(currentheight * tempMultiplier));
|
var newSize = new Size(System.Convert.ToInt32(currentwidth * tempMultiplier),
|
||||||
|
System.Convert.ToInt32(currentheight * tempMultiplier));
|
||||||
|
|
||||||
return newSize;
|
return newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -100,6 +100,20 @@ namespace ImageCatalog_2
|
||||||
NotifyPropertyChanged();
|
NotifyPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool UiDisabled => !_uiEnabled;
|
||||||
|
|
||||||
|
private string _speedCounter = "-";
|
||||||
|
|
||||||
|
public string SpeedCounter
|
||||||
|
{
|
||||||
|
get => _speedCounter;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_speedCounter = value;
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Test(object parameter)
|
private void Test(object parameter)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
876
imagecatalog/MainForm.Designer.cs
generated
876
imagecatalog/MainForm.Designer.cs
generated
File diff suppressed because it is too large
Load diff
|
|
@ -19,26 +19,25 @@ using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace ImageCatalog;
|
namespace ImageCatalog;
|
||||||
|
|
||||||
public delegate void XyThreadAdd(string Info);
|
|
||||||
|
|
||||||
public partial class MainForm
|
public partial class MainForm
|
||||||
{
|
{
|
||||||
private readonly DataModel Model;
|
private readonly DataModel Model;
|
||||||
|
|
||||||
private readonly ILogger<MainForm> _logger;
|
private readonly ILogger<MainForm> _logger;
|
||||||
|
|
||||||
private readonly ImageCreationStuff _imageCreationService;
|
private readonly ImageCreationStuff _imageCreationService;
|
||||||
|
|
||||||
private readonly ParametriSetup _parametriSetup;
|
private readonly ParametriSetup _parametriSetup;
|
||||||
private readonly PicSettings _picSettings;
|
private readonly PicSettings _picSettings;
|
||||||
|
|
||||||
public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings, ParametriSetup parametriSetup, ILogger<MainForm> logger)
|
public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings,
|
||||||
|
ParametriSetup parametriSetup, ILogger<MainForm> logger)
|
||||||
{
|
{
|
||||||
Model = model;
|
Model = model;
|
||||||
_imageCreationService = imageCreationStuff;
|
_imageCreationService = imageCreationStuff;
|
||||||
_parametriSetup = parametriSetup;
|
_parametriSetup = parametriSetup;
|
||||||
_picSettings = picSettings;
|
_picSettings = picSettings;
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_logger.LogDebug("Start");
|
_logger.LogDebug("Start");
|
||||||
|
|
@ -97,7 +96,7 @@ public partial class MainForm
|
||||||
{
|
{
|
||||||
if (InvokeRequired)
|
if (InvokeRequired)
|
||||||
{
|
{
|
||||||
SetProgressCallback d = new SetProgressCallback(SetProgress);
|
var d = new SetProgressCallback(SetProgress);
|
||||||
this.Invoke(d, new object[] { target, amount, maximum });
|
this.Invoke(d, new object[] { target, amount, maximum });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -121,7 +120,7 @@ public partial class MainForm
|
||||||
|
|
||||||
// Private ContaFotoCuori As Integer
|
// Private ContaFotoCuori As Integer
|
||||||
// Private TaskCuori() As PicInfo
|
// Private TaskCuori() As PicInfo
|
||||||
|
|
||||||
private int ContaImmaginiThread;
|
private int ContaImmaginiThread;
|
||||||
private int maxThreads = 15;
|
private int maxThreads = 15;
|
||||||
private int minThreads = 5;
|
private int minThreads = 5;
|
||||||
|
|
@ -206,11 +205,8 @@ public partial class MainForm
|
||||||
bindingSource1.DataSource = Model;
|
bindingSource1.DataSource = Model;
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
SetDefaults();
|
SetDefaults();
|
||||||
// /* TODO ERROR: Skipped IfDirectiveTrivia */
|
|
||||||
// AllocConsole();
|
|
||||||
// /* TODO ERROR: Skipped EndIfDirectiveTrivia */
|
|
||||||
_logger.LogInformation("Programma Avviato");
|
_logger.LogInformation("Programma Avviato");
|
||||||
//Console.WriteLine("Programma avviato");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FixPaths()
|
private void FixPaths()
|
||||||
|
|
@ -261,17 +257,17 @@ public partial class MainForm
|
||||||
{
|
{
|
||||||
long timediffH, timediffS;
|
long timediffH, timediffS;
|
||||||
long timediffM;
|
long timediffM;
|
||||||
|
|
||||||
TimeSpan timeDiff = timeStop - timeStart;
|
TimeSpan timeDiff = timeStop - timeStart;
|
||||||
|
|
||||||
timediffM = (int)timeDiff.TotalMinutes;
|
timediffM = (int)timeDiff.TotalMinutes;
|
||||||
timediffS = (int)timeDiff.TotalSeconds;
|
timediffS = (int)timeDiff.TotalSeconds;
|
||||||
timediffH = (int)timeDiff.TotalHours;
|
timediffH = (int)timeDiff.TotalHours;
|
||||||
|
|
||||||
// timediffM = DateAndTime.DateDiff(DateInterval.Minute, timeStart, timeStop);
|
// timediffM = DateAndTime.DateDiff(DateInterval.Minute, timeStart, timeStop);
|
||||||
// timediffS = DateAndTime.DateDiff(DateInterval.Second, timeStart, timeStop);
|
// timediffS = DateAndTime.DateDiff(DateInterval.Second, timeStart, timeStop);
|
||||||
// timediffH = DateAndTime.DateDiff(DateInterval.Hour, timeStart, timeStop);
|
// timediffH = DateAndTime.DateDiff(DateInterval.Hour, timeStart, timeStop);
|
||||||
|
|
||||||
double fotoSec = numFoto / (double)timediffS;
|
double fotoSec = numFoto / (double)timediffS;
|
||||||
double fotoMin = numFoto / (double)timediffM;
|
double fotoMin = numFoto / (double)timediffM;
|
||||||
double fotoOra = numFoto / (double)timediffH;
|
double fotoOra = numFoto / (double)timediffH;
|
||||||
|
|
@ -286,7 +282,7 @@ public partial class MainForm
|
||||||
var dialog = new FolderBrowserDialog();
|
var dialog = new FolderBrowserDialog();
|
||||||
dialog.InitialDirectory = startingFolder;
|
dialog.InitialDirectory = startingFolder;
|
||||||
if (dialog.ShowDialog() != DialogResult.OK) return string.Empty;
|
if (dialog.ShowDialog() != DialogResult.OK) return string.Empty;
|
||||||
|
|
||||||
var directoryScelta = FixPath(dialog.SelectedPath); // dialog.FileName;
|
var directoryScelta = FixPath(dialog.SelectedPath); // dialog.FileName;
|
||||||
|
|
||||||
return directoryScelta;
|
return directoryScelta;
|
||||||
|
|
@ -319,7 +315,7 @@ public partial class MainForm
|
||||||
SaveFileDlg.FilterIndex = 0;
|
SaveFileDlg.FilterIndex = 0;
|
||||||
SaveFileDlg.RestoreDirectory = true;
|
SaveFileDlg.RestoreDirectory = true;
|
||||||
if (DialogResult.OK != SaveFileDlg.ShowDialog()) return;
|
if (DialogResult.OK != SaveFileDlg.ShowDialog()) return;
|
||||||
|
|
||||||
var ilNome = SaveFileDlg.FileName;
|
var ilNome = SaveFileDlg.FileName;
|
||||||
_parametriSetup.NomeFileSetup = ilNome;
|
_parametriSetup.NomeFileSetup = ilNome;
|
||||||
_parametriSetup.AggiornaParametro("DirSorgente", Model.SourcePath);
|
_parametriSetup.AggiornaParametro("DirSorgente", Model.SourcePath);
|
||||||
|
|
@ -478,7 +474,7 @@ public partial class MainForm
|
||||||
if (PictureBox1.Image.Height >= PictureBox1.Image.Width)
|
if (PictureBox1.Image.Height >= PictureBox1.Image.Width)
|
||||||
{
|
{
|
||||||
PictureBox1.Height = 160;
|
PictureBox1.Height = 160;
|
||||||
PictureBox1.Width =
|
PictureBox1.Width =
|
||||||
(int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
|
(int)(160 * PictureBox1.Image.Width / (double)PictureBox1.Image.Height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -699,7 +695,7 @@ public partial class MainForm
|
||||||
|
|
||||||
return numerazioneType;
|
return numerazioneType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void CopyDirectoryFile(string SourcePath, string DestPath, bool OverWrite = false)
|
private void CopyDirectoryFile(string SourcePath, string DestPath, bool OverWrite = false)
|
||||||
{
|
{
|
||||||
|
|
@ -774,8 +770,6 @@ public partial class MainForm
|
||||||
{
|
{
|
||||||
_logger.LogError(exception.Message);
|
_logger.LogError(exception.Message);
|
||||||
_logger.LogInformation("Ignora questo errore");
|
_logger.LogInformation("Ignora questo errore");
|
||||||
// Console.WriteLine(exception);
|
|
||||||
// Console.WriteLine("Ignora questo errore");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockUI();
|
unlockUI();
|
||||||
|
|
@ -911,20 +905,20 @@ public partial class MainForm
|
||||||
_mainToken?.Dispose();
|
_mainToken?.Dispose();
|
||||||
_mainToken = new CancellationTokenSource();
|
_mainToken = new CancellationTokenSource();
|
||||||
var token = _mainToken.Token;
|
var token = _mainToken.Token;
|
||||||
|
|
||||||
// timeStart = TimeOfDay
|
// timeStart = TimeOfDay
|
||||||
FixPaths();
|
FixPaths();
|
||||||
Label10.Text = "Elaborazione in corso...";
|
Label10.Text = "Elaborazione in corso...";
|
||||||
lblFotoTotaliNum.Text = "0";
|
lblFotoTotaliNum.Text = "0";
|
||||||
Label18.Text = "0";
|
Label18.Text = "0";
|
||||||
Label43.Text = "-s";
|
Model.SpeedCounter = "-s";
|
||||||
SetPicSettings(Model.SourcePath, Model.DestinationPath);
|
SetPicSettings(Model.SourcePath, Model.DestinationPath);
|
||||||
ProgressBar1.Minimum = 0;
|
ProgressBar1.Minimum = 0;
|
||||||
ProgressBar1.Step = 1;
|
ProgressBar1.Step = 1;
|
||||||
ProgressBar1.Value = 0;
|
ProgressBar1.Value = 0;
|
||||||
|
|
||||||
// Await CreaCatalogoParallel()
|
// Await CreaCatalogoParallel()
|
||||||
|
|
||||||
var imageCreationOptions = new ImageCreationStuff.Options
|
var imageCreationOptions = new ImageCreationStuff.Options
|
||||||
{
|
{
|
||||||
AggiornaSottodirectory = chkAggiornaSottodirectory.Checked,
|
AggiornaSottodirectory = chkAggiornaSottodirectory.Checked,
|
||||||
|
|
@ -950,14 +944,14 @@ public partial class MainForm
|
||||||
timer1.Interval = 1000 * 60;
|
timer1.Interval = 1000 * 60;
|
||||||
timer1.Enabled = true;
|
timer1.Enabled = true;
|
||||||
|
|
||||||
string time = await _imageCreationService.CreaCatalogoParallel(imageCreationOptions, _results, UiUpdateEvent, token);
|
string time =
|
||||||
Label43.Text = time;
|
await _imageCreationService.CreaCatalogoParallel(imageCreationOptions, _results, UiUpdateEvent, token);
|
||||||
|
Model.SpeedCounter = time;
|
||||||
timer1.Enabled = false;
|
timer1.Enabled = false;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException operationCanceledException)
|
catch (OperationCanceledException operationCanceledException)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Operazione Cancellata");
|
_logger.LogInformation("Operazione Cancellata");
|
||||||
//Console.WriteLine("Operazione cancellata");
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -979,7 +973,8 @@ public partial class MainForm
|
||||||
_previousAmount = _currentAmount;
|
_previousAmount = _currentAmount;
|
||||||
_currentAmount = _results.Count;
|
_currentAmount = _results.Count;
|
||||||
int diff = _currentAmount - _previousAmount;
|
int diff = _currentAmount - _previousAmount;
|
||||||
SetText(Label43, $"{diff} f/m");
|
Model.SpeedCounter = $"{diff} f/m";
|
||||||
|
//SetText(Label43, $"{diff} f/m");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCounter(string text)
|
private void UpdateCounter(string text)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue