modernized picsettings

This commit is contained in:
Marco 2025-07-28 10:22:08 +02:00
commit 63aac7f911
5 changed files with 243 additions and 915 deletions

View file

@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging;
namespace MaddoShared
{
public class ImageCreationStuff(ILogger<ImageCreationStuff> logger)
public class ImageCreationStuff(ILogger<ImageCreationStuff> logger, PicSettings picSettings)
{
public class Options
{
@ -62,9 +62,9 @@ namespace MaddoShared
Bitmap logoBmp = null;
// Load Logo
if (PicSettings.LogoAggiungi & File.Exists(PicSettings.LogoNomeFile))
if (picSettings.LogoAggiungi & File.Exists(picSettings.LogoNomeFile))
{
logoBmp = new Bitmap(PicSettings.LogoNomeFile);
logoBmp = new Bitmap(picSettings.LogoNomeFile);
}
Func<FileData, Task> processFile = async fileData =>
@ -72,7 +72,7 @@ namespace MaddoShared
using var logoCopy = logoBmp.Clone(new Rectangle(0, 0, logoBmp.Width, logoBmp.Height),
logoBmp.PixelFormat);
using var imgCreator = new ImageCreatorSharp(fileData.File, fileData.Directory);
using var imgCreator = new ImageCreatorSharp(fileData.File, fileData.Directory, picSettings);
await imgCreator.CreaImmagineThread(fileData.File.Name, logoCopy);
results.Add(fileData.File.Name);

View file

@ -58,6 +58,8 @@ public class ImageCreatorSharp : IDisposable
private Orientations _orientation;
private DateTime? _creationDate;
private readonly PicSettings _picSettings;
public ImageCreatorSharp()
{
}
@ -77,8 +79,9 @@ public class ImageCreatorSharp : IDisposable
this.DestDir = destDir;
}
public ImageCreatorSharp(FileInfo file, DirectoryInfo destination)
public ImageCreatorSharp(FileInfo file, DirectoryInfo destination, PicSettings picSettings)
{
_picSettings = picSettings;
this.WorkFile = file;
this.DestDir = destination;
}
@ -104,7 +107,7 @@ public class ImageCreatorSharp : IDisposable
// Forza jpeg se è selezionata l'opzione
System.Drawing.Imaging.ImageFormat thisFormat = g.RawFormat;
if (PicSettings.UsaForzaJpg == true)
if (_picSettings.UsaForzaJpg == true)
thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
prepareThumbnailSize(g);
@ -128,7 +131,7 @@ public class ImageCreatorSharp : IDisposable
//GC.Collect();
}
// PicSettings.mainForm.stepProgressBar()
// _picSettings.mainForm.stepProgressBar()
catch (Exception ex)
{
@ -179,7 +182,7 @@ public class ImageCreatorSharp : IDisposable
FotoRuotaADestra = false;
FotoRuotaASinistra = false;
if (PicSettings.UsaRotazioneAutomatica == true)
if (_picSettings.UsaRotazioneAutomatica == true)
{
if (g.PropertyIdList.Length > 0)
{
@ -215,24 +218,24 @@ public class ImageCreatorSharp : IDisposable
/// ''' <remarks></remarks>
private void impostaTestoExtra(Image g)
{
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)
{
//ExifReader DatiExif = new ExifReader((Bitmap)g);
dataFoto = _creationDate ?? DateTime.Now; //DatiExif.DateTimeOriginal;
testoFirma = PicSettings.TestoFirmaStart;
testoFirmaV = PicSettings.TestoFirmaStartV;
testoFirma = _picSettings.TestoFirmaStart;
testoFirmaV = _picSettings.TestoFirmaStartV;
if (dataFoto.Year != 1)
{
testoFirmaPiccola = dataFoto.ToShortTimeString();
if (PicSettings.UsaOrarioTestoApplicare == true)
if (_picSettings.UsaOrarioTestoApplicare == true)
{
testoFirma += " " + dataFoto.ToShortDateString() + " " + dataFoto.ToLongTimeString();
testoFirmaV += " " + dataFoto.ToShortDateString() + " " + dataFoto.ToLongTimeString();
}
if (PicSettings.UsaTempoGaraTestoApplicare == true)
if (_picSettings.UsaTempoGaraTestoApplicare == true)
{
var diff = dataPartenzaI - dataFoto;
@ -247,8 +250,8 @@ public class ImageCreatorSharp : IDisposable
}
else
{
testoFirma = PicSettings.TestoFirmaStart;
testoFirmaV = PicSettings.TestoFirmaStartV;
testoFirma = _picSettings.TestoFirmaStart;
testoFirmaV = _picSettings.TestoFirmaStartV;
}
}
@ -258,11 +261,11 @@ public class ImageCreatorSharp : IDisposable
/// ''' <remarks></remarks>
private void preparaVariabili()
{
alphaScelta = System.Convert.ToInt32((255 * (100 - PicSettings.Trasparenza) / (double)100));
alphaScelta = System.Convert.ToInt32((255 * (100 - _picSettings.Trasparenza) / (double)100));
testoFirma = "";
testoFirmaV = "";
dataPartenzaI = PicSettings.DataPartenza;
testoOrario = PicSettings.TestoOrario;
dataPartenzaI = _picSettings.DataPartenza;
testoOrario = _picSettings.TestoOrario;
if (testoOrario.Length > 0)
testoOrario += " ";
testoFirmaPiccola = "";
@ -271,11 +274,11 @@ public class ImageCreatorSharp : IDisposable
nomeFileSmall = "";
nomeFileBig2 = "";
nomeFileBig = "";
DimensioneStandard = PicSettings.DimStandard;
DimensioneStandardMiniatura = PicSettings.DimStandardMiniatura;
DimensioneStandard = _picSettings.DimStandard;
DimensioneStandardMiniatura = _picSettings.DimStandardMiniatura;
// nomeFileSmall = Suffisso & NomeFileChild
// nomeFileBig = NomeFileChild
nomeFileSmall = PicSettings.Suffisso + WorkFile.Name;
nomeFileSmall = _picSettings.Suffisso + WorkFile.Name;
nomeFileBig = WorkFile.Name;
}
@ -283,13 +286,13 @@ public class ImageCreatorSharp : IDisposable
{
if (g.Width > g.Height)
{
thumbSizeSmall = NewthumbSize(g.Width, g.Height, PicSettings.LarghezzaSmall, "Larghezza");
thumbSizeSmall = NewthumbSize(g.Width, g.Height, _picSettings.LarghezzaSmall, "Larghezza");
Size SizeOrig = new Size(g.Width, g.Height);
thumbSizeBig = SizeOrig;
}
else
{
thumbSizeSmall = NewthumbSize(g.Width, g.Height, PicSettings.AltezzaSmall, "Altezza");
thumbSizeSmall = NewthumbSize(g.Width, g.Height, _picSettings.AltezzaSmall, "Altezza");
Size SizeOrig = new Size(g.Width, g.Height);
thumbSizeBig = SizeOrig;
}
@ -297,9 +300,9 @@ public class ImageCreatorSharp : IDisposable
private void creaMiniature(Image g, Bitmap imgOutputBig, ImageFormat thisFormat)
{
if (PicSettings.TestoMin)
if (_picSettings.TestoMin)
testoFirmaPiccola = nomeFileBig;
else if (PicSettings.AggNumTempMin)
else if (_picSettings.AggNumTempMin)
testoFirmaPiccola = nomeFileBig + " ";
// Dim yPosFromBottom4 As Single
@ -308,13 +311,13 @@ public class ImageCreatorSharp : IDisposable
SizeF crSize1 = new SizeF();
SizeF crSize2 = new SizeF();
if (PicSettings.CreaMiniature == true)
if (_picSettings.CreaMiniature == true)
{
if (PicSettings.AggiungiScritteMiniature == false)
if (_picSettings.AggiungiScritteMiniature == false)
{
if (string.Equals(PicSettings.DirectorySorgente, PicSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
nomeFileSmall = nomeFileSmall.Substring(0, nomeFileSmall.Length - 4) + PicSettings.Codice + nomeFileSmall.Substring(nomeFileSmall.Length - 4);
if (PicSettings.UsaOrarioMiniatura | PicSettings.TestoMin | PicSettings.AggTempoGaraMin | PicSettings.AggNumTempMin)
if (string.Equals(_picSettings.DirectorySorgente, _picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
nomeFileSmall = nomeFileSmall.Substring(0, nomeFileSmall.Length - 4) + _picSettings.Codice + nomeFileSmall.Substring(nomeFileSmall.Length - 4);
if (_picSettings.UsaOrarioMiniatura | _picSettings.TestoMin | _picSettings.AggTempoGaraMin | _picSettings.AggNumTempMin)
{
if (testoFirmaPiccola.Length > 0)
{
@ -327,15 +330,15 @@ public class ImageCreatorSharp : IDisposable
int LarghezzaStandard1;
// quick fix
DimensioneStandardMiniatura = 50;
if (PicSettings.Grassetto == true)
if (_picSettings.Grassetto == true)
{
crFont1 = new Font(PicSettings.IlFont, DimensioneStandardMiniatura, FontStyle.Bold);
crFont2 = new Font(PicSettings.IlFont, DimensioneStandard, FontStyle.Bold);
crFont1 = new Font(_picSettings.IlFont, DimensioneStandardMiniatura, FontStyle.Bold);
crFont2 = new Font(_picSettings.IlFont, DimensioneStandard, FontStyle.Bold);
}
else
{
crFont1 = new Font(PicSettings.IlFont, DimensioneStandardMiniatura);
crFont2 = new Font(PicSettings.IlFont, DimensioneStandard);
crFont1 = new Font(_picSettings.IlFont, DimensioneStandardMiniatura);
crFont2 = new Font(_picSettings.IlFont, DimensioneStandard);
}
crSize1 = grPhoto1.MeasureString(testoFirmaPiccola, crFont1);
@ -351,10 +354,10 @@ public class ImageCreatorSharp : IDisposable
Conta -= 5;
else
Conta -= 1;
if (PicSettings.Grassetto == true)
crFont1 = new Font(PicSettings.IlFont, Conta, FontStyle.Bold);
if (_picSettings.Grassetto == true)
crFont1 = new Font(_picSettings.IlFont, Conta, FontStyle.Bold);
else
crFont1 = new Font(PicSettings.IlFont, Conta);
crFont1 = new Font(_picSettings.IlFont, Conta);
crSize1 = grPhoto1.MeasureString(testoFirmaPiccola, crFont1);
if (crSize1.Width < System.Convert.ToSingle(g.Width))
{
@ -369,19 +372,19 @@ public class ImageCreatorSharp : IDisposable
DimensioneStandardMiniatura = Conta;
}
switch (PicSettings.Posizione.ToUpper())
switch (_picSettings.Posizione.ToUpper())
{
case "ALTO":
{
yPosFromBottom1 = (PicSettings.Margine);
yPosFromBottom4 = (PicSettings.MargVert);
yPosFromBottom1 = (_picSettings.Margine);
yPosFromBottom4 = (_picSettings.MargVert);
break;
}
case "BASSO":
{
yPosFromBottom1 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * PicSettings.Margine / (double)100)));
yPosFromBottom4 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * PicSettings.MargVert / (double)100)));
yPosFromBottom1 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * _picSettings.Margine / (double)100)));
yPosFromBottom4 = System.Convert.ToSingle((g.Height - crSize1.Height - (g.Height * _picSettings.MargVert / (double)100)));
break;
}
}
@ -389,13 +392,13 @@ public class ImageCreatorSharp : IDisposable
float xCenterOfImg1 = 0;
StringFormat StrFormat1 = new StringFormat();
switch (PicSettings.Allineamento.ToUpper())
switch (_picSettings.Allineamento.ToUpper())
{
case "SINISTRA":
{
xCenterOfImg1 = System.Convert.ToSingle((PicSettings.Margine + (LarghezzaStandard1 / (double)2)));
xCenterOfImg1 = System.Convert.ToSingle((_picSettings.Margine + (LarghezzaStandard1 / (double)2)));
if ((LarghezzaStandard1 / (double)2) > (g.Width / (double)2) - PicSettings.Margine)
if ((LarghezzaStandard1 / (double)2) > (g.Width / (double)2) - _picSettings.Margine)
xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
break;
}
@ -408,9 +411,9 @@ public class ImageCreatorSharp : IDisposable
case "DESTRA":
{
xCenterOfImg1 = System.Convert.ToSingle((g.Width - PicSettings.Margine - (LarghezzaStandard1 / (double)2)));
xCenterOfImg1 = System.Convert.ToSingle((g.Width - _picSettings.Margine - (LarghezzaStandard1 / (double)2)));
if ((LarghezzaStandard1 / (double)2) > (g.Width / (double)2) - PicSettings.Margine)
if ((LarghezzaStandard1 / (double)2) > (g.Width / (double)2) - _picSettings.Margine)
xCenterOfImg1 = System.Convert.ToSingle((g.Width / (double)2));
break;
}
@ -418,22 +421,22 @@ public class ImageCreatorSharp : IDisposable
StrFormat1.Alignment = StringAlignment.Center;
SolidBrush semiTransBrush21 = new SolidBrush(Color.FromArgb(alphaScelta, 0, 0, 0));
SolidBrush semiTransBrush1 = new SolidBrush(Color.FromArgb(alphaScelta, PicSettings.FontColoreRGB));
SolidBrush semiTransBrush1 = new SolidBrush(Color.FromArgb(alphaScelta, _picSettings.FontColoreRGB));
// quick fix
DimensioneStandardMiniatura = PicSettings.DimMin;
DimensioneStandardMiniatura = _picSettings.DimMin;
if (PicSettings.Grassetto == true)
crFont1 = new Font(PicSettings.IlFont, DimensioneStandardMiniatura, FontStyle.Bold);
if (_picSettings.Grassetto == true)
crFont1 = new Font(_picSettings.IlFont, DimensioneStandardMiniatura, FontStyle.Bold);
else
crFont1 = new Font(PicSettings.IlFont, DimensioneStandardMiniatura);
crFont1 = new Font(_picSettings.IlFont, DimensioneStandardMiniatura);
// asdgadfhdfhjgfsjgfjygfdhsdafa
if (PicSettings.TestoMin)
if (_picSettings.TestoMin)
{
grPhoto1.DrawString(nomeFileBig, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1);
grPhoto1.DrawString(nomeFileBig, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1);
}
else if (PicSettings.AggTempoGaraMin & PicSettings.UsaTempoGaraTestoApplicare)
else if (_picSettings.AggTempoGaraMin & _picSettings.UsaTempoGaraTestoApplicare)
{
var diff = dataPartenzaI - dataFoto;
var diffA = diff.TotalSeconds * 10000000;
@ -448,7 +451,7 @@ public class ImageCreatorSharp : IDisposable
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1);
grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1);
}
else if (PicSettings.AggNumTempMin)
else if (_picSettings.AggNumTempMin)
{
var diff = dataPartenzaI - dataFoto;
var diffA = diff.TotalSeconds * 10000000;
@ -515,10 +518,10 @@ public class ImageCreatorSharp : IDisposable
SizeF crSize = new SizeF();
int LarghezzaStandard;
if (PicSettings.Grassetto == true)
crFont = new Font(PicSettings.IlFont, DimensioneStandard, FontStyle.Bold);
if (_picSettings.Grassetto == true)
crFont = new Font(_picSettings.IlFont, DimensioneStandard, FontStyle.Bold);
else
crFont = new Font(PicSettings.IlFont, DimensioneStandard);
crFont = new Font(_picSettings.IlFont, DimensioneStandard);
crSize = grPhoto.MeasureString(testoFirma, crFont);
LarghezzaStandard = System.Convert.ToInt32(crSize.Width);
@ -531,10 +534,10 @@ public class ImageCreatorSharp : IDisposable
Conta -= 5;
else
Conta -= 1;
if (PicSettings.Grassetto == true)
crFont = new Font(PicSettings.IlFont, Conta, FontStyle.Bold);
if (_picSettings.Grassetto == true)
crFont = new Font(_picSettings.IlFont, Conta, FontStyle.Bold);
else
crFont = new Font(PicSettings.IlFont, Conta);
crFont = new Font(_picSettings.IlFont, Conta);
crSize = grPhoto.MeasureString(testoFirma, crFont);
if (crSize.Width < System.Convert.ToSingle(g.Width))
{
@ -550,19 +553,19 @@ public class ImageCreatorSharp : IDisposable
}
switch (PicSettings.Posizione.ToUpper())
switch (_picSettings.Posizione.ToUpper())
{
case "ALTO":
{
yPosFromBottom = (PicSettings.Margine);
yPosFromBottom3 = (PicSettings.MargVert);
yPosFromBottom = (_picSettings.Margine);
yPosFromBottom3 = (_picSettings.MargVert);
break;
}
case "BASSO":
{
yPosFromBottom = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * PicSettings.Margine / (double)100)));
yPosFromBottom3 = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * PicSettings.MargVert / (double)100)));
yPosFromBottom = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * _picSettings.Margine / (double)100)));
yPosFromBottom3 = System.Convert.ToSingle((g.Height - crSize.Height - (g.Height * _picSettings.MargVert / (double)100)));
break;
}
}
@ -570,15 +573,15 @@ public class ImageCreatorSharp : IDisposable
float xCenterOfImg = 0;
float xCenterOfImg3 = 0;
StringFormat StrFormat = new StringFormat();
switch (PicSettings.Allineamento.ToUpper())
switch (_picSettings.Allineamento.ToUpper())
{
case "SINISTRA":
{
xCenterOfImg = System.Convert.ToSingle((PicSettings.Margine + (LarghezzaStandard / (double)2)));
xCenterOfImg3 = System.Convert.ToSingle((PicSettings.MargVert + (LarghezzaStandard / (double)2)));
if ((LarghezzaStandard / (double)2) > (g.Width / (double)2) - PicSettings.Margine)
xCenterOfImg = System.Convert.ToSingle((_picSettings.Margine + (LarghezzaStandard / (double)2)));
xCenterOfImg3 = System.Convert.ToSingle((_picSettings.MargVert + (LarghezzaStandard / (double)2)));
if ((LarghezzaStandard / (double)2) > (g.Width / (double)2) - _picSettings.Margine)
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)
xCenterOfImg3 = System.Convert.ToSingle((g.Width / (double)2));
break;
}
@ -591,11 +594,11 @@ public class ImageCreatorSharp : IDisposable
case "DESTRA":
{
xCenterOfImg = 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)
xCenterOfImg = 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)
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)
xCenterOfImg3 = System.Convert.ToSingle((g.Width / (double)2));
break;
}
@ -604,25 +607,25 @@ public class ImageCreatorSharp : IDisposable
SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(alphaScelta, 0, 0, 0));
// Dim semiTransBrush As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB))
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(alphaScelta, PicSettings.FontColoreRGB));
SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(alphaScelta, _picSettings.FontColoreRGB));
if (FotoRuotaADestra | FotoRuotaASinistra)
{
if (PicSettings.Grassetto == true)
crFont = new Font(PicSettings.IlFont, PicSettings.DimVert, FontStyle.Bold);
if (_picSettings.Grassetto == true)
crFont = new Font(_picSettings.IlFont, _picSettings.DimVert, FontStyle.Bold);
else
crFont = new Font(PicSettings.IlFont, PicSettings.DimVert);
crFont = new Font(_picSettings.IlFont, _picSettings.DimVert);
}
else if (PicSettings.Grassetto == true)
crFont = new Font(PicSettings.IlFont, DimensioneStandard, FontStyle.Bold);
else if (_picSettings.Grassetto == true)
crFont = new Font(_picSettings.IlFont, DimensioneStandard, FontStyle.Bold);
else
crFont = new Font(PicSettings.IlFont, DimensioneStandard);
crFont = new Font(_picSettings.IlFont, DimensioneStandard);
// qui scrive il testo (nomefilebig)
if (PicSettings.TestoNome)
if (_picSettings.TestoNome)
{
if (PicSettings.NomeData & g.PropertyIdList.Length > 0)
if (_picSettings.NomeData & g.PropertyIdList.Length > 0)
{
//ExifReader DatiExif = new ExifReader((Bitmap)g);
dataFoto = _creationDate ?? DateTime.Now; //DatiExif.DateTimeOriginal;
@ -637,16 +640,16 @@ public class ImageCreatorSharp : IDisposable
}
}
if (PicSettings.TestoNome == false)
if (_picSettings.TestoNome == false)
{
if (FotoRuotaADestra | FotoRuotaASinistra)
{
if (PicSettings.TestoMin == false)
if (_picSettings.TestoMin == false)
{
grPhoto.DrawString(testoFirmaV, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, yPosFromBottom3 + 1), StrFormat);
grPhoto.DrawString(testoFirmaV, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom3), StrFormat);
}
if (PicSettings.TestoMin == true)
if (_picSettings.TestoMin == true)
{
grPhoto.DrawString(testoFirmaV, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1, yPosFromBottom4 + 1), StrFormat);
grPhoto.DrawString(testoFirmaV, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom4), StrFormat);
@ -659,10 +662,10 @@ public class ImageCreatorSharp : IDisposable
}
}
if (string.Equals(PicSettings.DirectorySorgente, PicSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
if (string.Equals(_picSettings.DirectorySorgente, _picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
{
nomeFileBig2 = nomeFileBig;
nomeFileBig = nomeFileBig.Substring(0, nomeFileBig.Length - 4) + PicSettings.Codice + nomeFileBig.Substring(nomeFileBig.Length - 4);
nomeFileBig = nomeFileBig.Substring(0, nomeFileBig.Length - 4) + _picSettings.Codice + nomeFileBig.Substring(nomeFileBig.Length - 4);
}
//grPhoto.Dispose();
@ -675,9 +678,9 @@ public class ImageCreatorSharp : IDisposable
private void aggiungiLogo(Bitmap imgOutputBig, Image logo)
{
// imgOutputBig
if (PicSettings.LogoAggiungi == true & File.Exists(PicSettings.LogoNomeFile))
if (_picSettings.LogoAggiungi == true & File.Exists(_picSettings.LogoNomeFile))
{
// using var ImmagineLogo = Image.FromFile(PicSettings.LogoNomeFile);
// using var ImmagineLogo = Image.FromFile(_picSettings.LogoNomeFile);
Color LogoColoreTrasparente = Color.White;
@ -696,12 +699,12 @@ public class ImageCreatorSharp : IDisposable
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
float[][] 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 } };
float[][] 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 } };
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
int FotoLogoH = PicSettings.LogoAltezza;
int FotoLogoW = PicSettings.LogoLarghezza;
int FotoLogoH = _picSettings.LogoAltezza;
int FotoLogoW = _picSettings.LogoLarghezza;
double FattoreAlt = logo.Height / (double)FotoLogoH;
double FattoreLarg = logo.Width / (double)FotoLogoW;
Size NuovaSize;
@ -713,11 +716,11 @@ public class ImageCreatorSharp : IDisposable
int MargineUsato;
int MargineL;
bool InPercentualeL;
if (PicSettings.LogoMargine.EndsWith("%") == true)
if (_picSettings.LogoMargine.EndsWith("%") == true)
InPercentualeL = true;
else
InPercentualeL = false;
MargineL = System.Convert.ToInt32(PicSettings.LogoMargine);
MargineL = System.Convert.ToInt32(_picSettings.LogoMargine);
if (InPercentualeL == true)
MargineUsato = System.Convert.ToInt32(imgOutputBig.Height * MargineL / (double)100);
else
@ -725,7 +728,7 @@ public class ImageCreatorSharp : IDisposable
int xPosOfWm = 0;
int yPosOfWm = 0;
switch (PicSettings.LogoPosizioneH.ToUpper())
switch (_picSettings.LogoPosizioneH.ToUpper())
{
case "SINISTRA":
case "NESSUNA":
@ -746,7 +749,7 @@ public class ImageCreatorSharp : IDisposable
break;
}
}
switch (PicSettings.LogoPosizioneV.ToUpper())
switch (_picSettings.LogoPosizioneV.ToUpper())
{
case "ALTO":
case "NESSUNA":
@ -777,7 +780,7 @@ public class ImageCreatorSharp : IDisposable
private void SalvaFoto(Bitmap imgOutputBig, Size thumbSizeBig, string NomeFileBig, string NomeFileSmall, Size thumbSizeSmall, ImageFormat thisFormat)
{
using var image1Stream = new MemoryStream();
if (PicSettings.FotoGrandeDimOrigina == false)
if (_picSettings.FotoGrandeDimOrigina == false)
{
// attenzione non controlla se è png
// imgOutputBig.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig), thisFormat)
@ -785,7 +788,7 @@ public class ImageCreatorSharp : IDisposable
{
MakeImageCustomQuality(imgOutputBig, image1Stream);
}
//SalvaImmagineCustomQuality(imgOutputBig, Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig), PicSettings.jpegQuality);
//SalvaImmagineCustomQuality(imgOutputBig, Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig), _picSettings.jpegQuality);
else
{
imgOutputBig.Save(image1Stream, thisFormat);
@ -793,10 +796,10 @@ public class ImageCreatorSharp : IDisposable
//imgOutputBig.Save(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig), thisFormat);
image1Stream.Seek(0, SeekOrigin.Begin);
using var g2 = Image.FromStream(image1Stream);
thumbSizeBig = g2.Width > g2.Height ? NewthumbSize(g2.Width, g2.Height, PicSettings.LarghezzaBig, "Larghezza") : NewthumbSize(g2.Width, g2.Height, PicSettings.AltezzaBig, "Altezza");
thumbSizeBig = g2.Width > g2.Height ? NewthumbSize(g2.Width, g2.Height, _picSettings.LarghezzaBig, "Larghezza") : NewthumbSize(g2.Width, g2.Height, _picSettings.AltezzaBig, "Altezza");
using Bitmap imgOutputBig2 = new Bitmap(g2, thumbSizeBig.Width, thumbSizeBig.Height);
if (thisFormat.Equals(ImageFormat.Jpeg))
SalvaImmagineCustomQuality(imgOutputBig2, Path.Combine(DestDir.FullName, NomeFileBig), PicSettings.JpegQuality);
SalvaImmagineCustomQuality(imgOutputBig2, Path.Combine(DestDir.FullName, NomeFileBig), _picSettings.JpegQuality);
else
imgOutputBig2.Save(Path.Combine(DestDir.FullName, NomeFileBig), thisFormat);
@ -809,7 +812,7 @@ public class ImageCreatorSharp : IDisposable
{
//
if (thisFormat.Equals(ImageFormat.Jpeg))
SalvaImmagineCustomQuality(imgOutputBig, Path.Combine(DestDir.FullName, NomeFileBig), PicSettings.JpegQuality);
SalvaImmagineCustomQuality(imgOutputBig, Path.Combine(DestDir.FullName, NomeFileBig), _picSettings.JpegQuality);
else
imgOutputBig.Save(Path.Combine(DestDir.FullName, NomeFileBig), thisFormat);
@ -817,23 +820,23 @@ public class ImageCreatorSharp : IDisposable
}
image1Stream.Seek(0, SeekOrigin.Begin);
if (PicSettings.CreaMiniature)
if (_picSettings.CreaMiniature)
{
if (PicSettings.AggiungiScritteMiniature)
if (_picSettings.AggiungiScritteMiniature)
{
using System.Drawing.Image g1 = PicSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
//if (PicSettings.FotoGrandeDimOrigina == false)
using System.Drawing.Image g1 = _picSettings.FotoGrandeDimOrigina ? (Image)imgOutputBig.Clone() : Image.FromStream(image1Stream);
//if (_picSettings.FotoGrandeDimOrigina == false)
// g1 = Image.FromStream(image1Stream);
////g1 = System.Drawing.Image.FromFile(Path.Combine(DestDir.FullName, "Temp_" + NomeFileBig));
//else
// g1 = (Image)imgOutputBig.Clone();
//g1 = System.Drawing.Image.FromFile(Path.Combine(DestDir.FullName, NomeFileBig));
using Bitmap imgOutputSmall = new Bitmap(g1, thumbSizeSmall.Width, thumbSizeSmall.Height);
if (string.Equals(PicSettings.DirectorySorgente, PicSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + PicSettings.Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4);
if (string.Equals(_picSettings.DirectorySorgente, _picSettings.DirectoryDestinazione, StringComparison.OrdinalIgnoreCase))
NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + _picSettings.Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4);
//
if (thisFormat.Equals(ImageFormat.Jpeg))
SalvaImmagineCustomQuality(imgOutputSmall, Path.Combine(DestDir.FullName, NomeFileSmall), PicSettings.JpegQualityMin);
SalvaImmagineCustomQuality(imgOutputSmall, Path.Combine(DestDir.FullName, NomeFileSmall), _picSettings.JpegQualityMin);
else
imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat);
@ -854,7 +857,7 @@ public class ImageCreatorSharp : IDisposable
EncoderParameters MyEncoderParameters = new EncoderParameters(1);
EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, PicSettings.JpegQuality);
EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, _picSettings.JpegQuality);
MyEncoderParameters.Param[0] = MyEncoderParameter;
imageToSave.Save(nomeFileFinale, JgpEncoder, MyEncoderParameters);
//imageToSave.Dispose();
@ -867,7 +870,7 @@ public class ImageCreatorSharp : IDisposable
EncoderParameters MyEncoderParameters = new EncoderParameters(1);
EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, PicSettings.JpegQuality);
EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, _picSettings.JpegQuality);
MyEncoderParameters.Param[0] = MyEncoderParameter;
destinationStream.Seek(0, SeekOrigin.Begin);
imageToSave.Save(destinationStream, JgpEncoder, MyEncoderParameters);

View file

@ -5,63 +5,63 @@ using System.Windows.Forms;
namespace MaddoShared;
public static class PicSettings
public class PicSettings
{
public static string DirectorySorgente { get; set; }
public static string DirectoryDestinazione { get; set; }
public static string TestoFirmaStart { get; set; }
public static string TestoFirmaStartV { get; set; }
public static DateTime DataPartenza { get; set; }
public static string TestoOrario { get; set; }
public static int DimStandard { get; set; }
public static int DimStandardMiniatura { get; set; }
public static bool NomeData { get; set; }
public static bool TestoNome { get; set; }
public static bool UsaOrarioMiniatura { get; set; }
public static bool UsaOrarioTestoApplicare { get; set; }
public static bool UsaTempoGaraTestoApplicare { get; set; }
public static bool UsaRotazioneAutomatica { get; set; }
public static bool UsaForzaJpg { get; set; }
public static int LarghezzaSmall { get; set; }
public static int AltezzaSmall { get; set; }
public static bool CreaMiniature { get; set; }
public static bool AggiungiScritteMiniature { get; set; }
public static string Suffisso { get; set; }
public static string Codice { get; set; }
public static int Trasparenza { get; set; }
public static string IlFont { get; set; }
public static bool Grassetto { get; set; }
public static string Posizione { get; set; }
public static string Allineamento { get; set; }
public static int Margine { get; set; }
public static int LogoAltezza { get; set; }
public static int LogoLarghezza { get; set; }
public static Color FontColoreRGB { get; set; }
public static bool LogoAggiungi { get; set; }
public static string LogoNomeFile { get; set; }
public static string LogoTrasparenza { get; set; }
public static string LogoMargine { get; set; }
public static string LogoPosizioneH { get; set; }
public static string LogoPosizioneV { get; set; }
public static bool FotoGrandeDimOrigina { get; set; }
public static int AltezzaBig { get; set; }
public static int LarghezzaBig { get; set; }
public static DirectoryInfo DestDir { get; set; }
public static int DimVert { get; set; }
public static int MargVert { get; set; }
public static bool TestoMin { get; set; }
public static int DimMin { get; set; }
public static bool SecretDefault { get; set; }
public static bool SecretBig { get; set; }
public static bool SecretSmall { get; set; }
public static string SecretPathSmall { get; set; }
public static string SecretPathBig { get; set; }
public static bool AggTempoGaraMin { get; set; }
public static bool AggNumTempMin { get; set; }
public static long JpegQuality { get; set; }
public static long JpegQualityMin { get; set; }
public string DirectorySorgente { get; set; }
public string DirectoryDestinazione { get; set; }
public string TestoFirmaStart { get; set; }
public string TestoFirmaStartV { get; set; }
public DateTime DataPartenza { get; set; }
public string TestoOrario { get; set; }
public int DimStandard { get; set; }
public int DimStandardMiniatura { get; set; }
public bool NomeData { get; set; }
public bool TestoNome { get; set; }
public bool UsaOrarioMiniatura { get; set; }
public bool UsaOrarioTestoApplicare { get; set; }
public bool UsaTempoGaraTestoApplicare { get; set; }
public bool UsaRotazioneAutomatica { get; set; }
public bool UsaForzaJpg { get; set; }
public int LarghezzaSmall { get; set; }
public int AltezzaSmall { get; set; }
public bool CreaMiniature { get; set; }
public bool AggiungiScritteMiniature { get; set; }
public string Suffisso { get; set; }
public string Codice { get; set; }
public int Trasparenza { get; set; }
public string IlFont { get; set; }
public bool Grassetto { get; set; }
public string Posizione { get; set; }
public string Allineamento { get; set; }
public int Margine { get; set; }
public int LogoAltezza { get; set; }
public int LogoLarghezza { get; set; }
public Color FontColoreRGB { get; set; }
public bool LogoAggiungi { get; set; }
public string LogoNomeFile { get; set; }
public string LogoTrasparenza { get; set; }
public string LogoMargine { get; set; }
public string LogoPosizioneH { get; set; }
public string LogoPosizioneV { get; set; }
public bool FotoGrandeDimOrigina { get; set; }
public int AltezzaBig { get; set; }
public int LarghezzaBig { get; set; }
public DirectoryInfo DestDir { get; set; }
public int DimVert { get; set; }
public int MargVert { get; set; }
public bool TestoMin { get; set; }
public int DimMin { get; set; }
public bool SecretDefault { get; set; }
public bool SecretBig { get; set; }
public bool SecretSmall { get; set; }
public string SecretPathSmall { get; set; }
public string SecretPathBig { get; set; }
public bool AggTempoGaraMin { get; set; }
public bool AggNumTempMin { get; set; }
public long JpegQuality { get; set; }
public long JpegQualityMin { get; set; }
public static bool FotoRuotaADestra { get; set; } = false;
public static bool FotoRuotaASinistra { get; set; } = false;
public static string TempMinText { get; set; } = string.Empty;
public bool FotoRuotaADestra { get; set; } = false;
public bool FotoRuotaASinistra { get; set; } = false;
public string TempMinText { get; set; } = string.Empty;
}