From a21522a9166773d5bf36ef6fddc31db27a7a9fdf Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 28 Jul 2025 10:34:03 +0200 Subject: [PATCH] Cleaned up old code --- imagecatalog/AssemblyInfo.vb | 31 - imagecatalog/CreaImmagineSeparateMultiCore.cs | 1255 ------------ imagecatalog/CreaImmagineSeparateMultiCore.vb | 943 --------- imagecatalog/CreaImmagineSeparateThread.cs | 1721 ----------------- imagecatalog/CreaImmagineSeparateThread.vb | 1409 -------------- imagecatalog/DataModel.cs | 13 +- imagecatalog/ExifReader.vb | 1068 ---------- imagecatalog/FileHelper.vb | 252 --- imagecatalog/LoadBuffer.cs | 13 - imagecatalog/LoadBuffer.vb | 9 - imagecatalog/MainForm.Designer.cs | 1 + imagecatalog/MainForm.cs | 9 +- imagecatalog/ParametriSetup.vb | 167 -- imagecatalog/XYThreadPool.cs | 273 --- imagecatalog/XYThreadPool.vb | 185 -- 15 files changed, 17 insertions(+), 7332 deletions(-) delete mode 100644 imagecatalog/AssemblyInfo.vb delete mode 100644 imagecatalog/CreaImmagineSeparateMultiCore.cs delete mode 100644 imagecatalog/CreaImmagineSeparateMultiCore.vb delete mode 100644 imagecatalog/CreaImmagineSeparateThread.cs delete mode 100644 imagecatalog/CreaImmagineSeparateThread.vb delete mode 100644 imagecatalog/ExifReader.vb delete mode 100644 imagecatalog/FileHelper.vb delete mode 100644 imagecatalog/LoadBuffer.cs delete mode 100644 imagecatalog/LoadBuffer.vb delete mode 100644 imagecatalog/ParametriSetup.vb delete mode 100644 imagecatalog/XYThreadPool.cs delete mode 100644 imagecatalog/XYThreadPool.vb diff --git a/imagecatalog/AssemblyInfo.vb b/imagecatalog/AssemblyInfo.vb deleted file mode 100644 index 96c6530..0000000 --- a/imagecatalog/AssemblyInfo.vb +++ /dev/null @@ -1,31 +0,0 @@ -Imports System.Reflection -Imports System.Runtime.InteropServices - -' General Information about an assembly is controlled through the following -' set of attributes. Change these attribute values to modify the information -' associated with an assembly. - -' Review the values of the assembly attributes - - - - - - - - - -'The following GUID is for the ID of the typelib if this project is exposed to COM - - -' Version information for an assembly consists of the following four values: -' -' Major Version -' Minor Version -' Build Number -' Revision -' -' You can specify all the values or you can default the Build and Revision Numbers -' by using the '*' as shown below: - - diff --git a/imagecatalog/CreaImmagineSeparateMultiCore.cs b/imagecatalog/CreaImmagineSeparateMultiCore.cs deleted file mode 100644 index 8ead6eb..0000000 --- a/imagecatalog/CreaImmagineSeparateMultiCore.cs +++ /dev/null @@ -1,1255 +0,0 @@ -using System; -using System.Drawing; -using System.IO; -using Microsoft.VisualBasic; -using Microsoft.VisualBasic.CompilerServices; - -namespace ImageCatalog -{ - // Imports System.Drawing.Drawing2D - // Imports System.Drawing.Imaging - // Imports System.Threading - - public class CreaImmagineSeparateMultiCore - { - private string _DirectorySorgente; - private string _DirectoryDestinazione; - private DirectoryInfo _SourceDir; - private DirectoryInfo _DestDirStart; - private int _DimStandard; - private int _DimStandardMiniatura; - private bool _UsaOrarioMiniatura; - private bool _UsaOrarioTestoApplicare; - private bool _UsaTempoGaraTestoApplicare; - private string _TestoFirmaStart; - private string _TestoFirmaStartV; - private DateTime _DataPartenza; - private string _TestoOrario; - private bool _UsaRotazioneAutomatica; - private bool _UsaForzaJpg; - private int _LarghezzaSmall; - private int _AltezzaSmall; - private bool _CreaMiniature; - private bool _AggiungiScritteMiniature; - private string _NomeFileChild; - private string _Suffisso; - private string _Codice; - private int _Trasparenza; - private string _IlFont; - private bool _Grassetto; - private string _Posizione; - private string _Allineamento; - private int _Margine; - private int _LogoAltezza; - private int _LogoLarghezza; - private int _FontColoreR; - private int _FontColoreG; - private int _FontColoreB; - private bool _LogoAggiungi; - private string _LogoNomeFile; - private string _LogoTrasparenza; - private string _LogoMargine; - private string _LogoPosizioneH; - private string _LogoPosizioneV; - private bool _FotoGrandeDimOrigina; - private int _AltezzaBig; - private int _LarghezzaBig; - private DirectoryInfo _DestDir; - - public void CreaImmagine(PicInfo InfoImg) - { - string TestoFirma = ""; - _DestDir = InfoImg.DirDest; - _SourceDir = InfoImg.DirSource; - _DestDirStart = InfoImg.DirDestStart; - _NomeFileChild = InfoImg.NomeImmagine; - int AlphaScelta = Conversions.ToInteger(255 * (100 - _Trasparenza) / 100d); - int DimensioneStandard; - int DimensioneStandardMiniatura; - DateTime DataFoto; - var DataPartenzaI = _DataPartenza; - if (_TestoOrario.Length > 0) - { - _TestoOrario += " "; - } - - string TestoFirmaPiccola = ""; - int FileConta = 0; - int ContaFileXDir = 0; - int ContaDirXDir = 0; - string TestoTemp = ""; - int ContaTemp = 0; - DimensioneStandard = _DimStandard; - DimensioneStandardMiniatura = _DimStandardMiniatura; - var g = Image.FromFile(Path.Combine(_SourceDir.FullName, _NomeFileChild)); - if (_UsaOrarioTestoApplicare == true | _UsaTempoGaraTestoApplicare == true | _UsaOrarioMiniatura == true) - { - if (g.PropertyIdList.Length > 0) // ci sono dati exif - { - var DatiExif = new ExifReader((Bitmap)g); - DataFoto = DatiExif.DateTimeOriginal; - TestoFirma = _TestoFirmaStart; - if (DataFoto.Year != 1) - { - TestoFirmaPiccola = DataFoto.ToShortTimeString(); - if (_UsaOrarioTestoApplicare == true) - { - TestoFirma += " - " + DataFoto.ToShortDateString() + " " + DataFoto.ToLongTimeString(); - } - - if (_UsaTempoGaraTestoApplicare == true) - { - var Orario = new TimeSpan(DateAndTime.DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000L); - TestoFirma += " - " + _TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00"); - } - } - } - } - else - { - TestoFirma = _TestoFirmaStart; - } - - bool FotoRuotaADestra = false; - bool FotoRuotaASinistra = false; - if (_UsaRotazioneAutomatica == true) - { - if (g.PropertyIdList.Length > 0) // ci sono dati exif - { - var DatiExif = new ExifReader((Bitmap)g); - switch (DatiExif.Orientation) - { - case ExifReader.Orientations.BottomLeft: - { - break; - } - - case ExifReader.Orientations.BottomRight: - { - break; - } - - case ExifReader.Orientations.LeftTop: - { - break; - } - - case ExifReader.Orientations.LftBottom: - { - FotoRuotaASinistra = true; - break; - } - - case ExifReader.Orientations.RightBottom: - { - break; - } - - case ExifReader.Orientations.RightTop: - { - break; - } - - case ExifReader.Orientations.TopLeft: - { - break; - } - - case ExifReader.Orientations.TopRight: - { - break; - } - } - } - } - // rotazione - if (FotoRuotaASinistra == true) - { - g.RotateFlip(RotateFlipType.Rotate270FlipNone); - } - - if (FotoRuotaADestra == true) - { - g.RotateFlip(RotateFlipType.Rotate90FlipNone); - } - - var thisFormat = g.RawFormat; - if (_UsaForzaJpg == true) - { - thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg; - } - - var thumbSizeSmall = new Size(); - var thumbSizeBig = new Size(); - string NomeFileSmall = ""; - string NomeFileBig = ""; - string NomeFileBig2 = ""; - if (g.Width > g.Height) - { - thumbSizeSmall = NewthumbSize(g.Width, g.Height, LarghezzaSmall, "Larghezza"); - var SizeOrig = new Size(g.Width, g.Height); - thumbSizeBig = SizeOrig; - } - else - { - thumbSizeSmall = NewthumbSize(g.Width, g.Height, AltezzaSmall, "Altezza"); - var SizeOrig = new Size(g.Width, g.Height); - thumbSizeBig = SizeOrig; - } - - NomeFileSmall = Suffisso + _NomeFileChild; - NomeFileBig = _NomeFileChild; - var imgOutputBig = new Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height); - imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution); - if (_CreaMiniature == true) - { - if (_AggiungiScritteMiniature == false) - { - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4); - } - - if (_UsaOrarioMiniatura == true) - { - if (TestoFirmaPiccola.Length > 0) - { - Bitmap imgOutputSmall; - imgOutputSmall = (Bitmap)imgOutputBig.Clone(); - Graphics grPhoto1; - grPhoto1 = Graphics.FromImage(imgOutputSmall); - grPhoto1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; - Font crFont1 = null; - var crSize1 = new SizeF(); - int LarghezzaStandard1; - if (_Grassetto == true) - { - crFont1 = new Font(IlFont, DimensioneStandardMiniatura, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura); - } - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1); - LarghezzaStandard1 = Conversions.ToInteger(crSize1.Width); - if (crSize1.Width > Conversions.ToSingle(g.Width)) - { - int Conta = DimensioneStandardMiniatura; - do - { - if (Conta > 20) - { - Conta -= 5; - } - else - { - Conta -= 1; - } - - if (_Grassetto == true) - { - crFont1 = new Font(_IlFont, Conta, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, Conta); - } - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1); - if (crSize1.Width < Conversions.ToSingle(g.Width)) - { - LarghezzaStandard1 = Conversions.ToInteger(crSize1.Width); - break; - } - - if (Conta <= 5) - break; - } - while (true); - DimensioneStandardMiniatura = Conta; - } - - var yPosFromBottom1 = default(float); - switch (_Posizione.ToUpper() ?? "") - { - case "ALTO": - { - yPosFromBottom1 = _Margine; - break; - } - - case "BASSO": - { - // yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - // yPosFromBottom1 = CType((g.Height - crFont1.Height - (g.Height * _Margine / 100) - (crFont1.Height * 0.3)), Single) - yPosFromBottom1 = Conversions.ToSingle(g.Height - crSize1.Height - g.Height * _Margine / 100d); - break; - } - } - - var xCenterOfImg1 = default(float); - var StrFormat1 = new StringFormat(); - switch (_Allineamento.ToUpper() ?? "") - { - case "SINISTRA": - { - xCenterOfImg1 = Conversions.ToSingle(_Margine + LarghezzaStandard1 / 2d); - if (LarghezzaStandard1 / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - - case "CENTRO": - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - break; - } - - case "DESTRA": - { - xCenterOfImg1 = Conversions.ToSingle(g.Width - _Margine - LarghezzaStandard1 / 2d); - if (LarghezzaStandard1 / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - } - - StrFormat1.Alignment = StringAlignment.Center; - var semiTransBrush21 = new SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)); - var semiTransBrush1 = new SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)); - if (_Grassetto == true) - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura); - } - - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1f, yPosFromBottom1 + 1f), StrFormat1); - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1); - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall), thisFormat); - var g2 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall)); - var imgOutputSmall2 = new Bitmap(g2, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall2.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall2.Dispose(); - imgOutputSmall.Dispose(); - g2.Dispose(); - FileSystem.Kill(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall)); - } - else - { - var imgOutputSmall = new Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall.Dispose(); - } - } - else - { - var imgOutputSmall = new Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall.Dispose(); - } - } - } - - Graphics grPhoto; - grPhoto = Graphics.FromImage(imgOutputBig); - grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; - Font crFont = null; - var crSize = new SizeF(); - int LarghezzaStandard; - if (_Grassetto == true) - { - crFont = new Font(_IlFont, DimensioneStandard, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, DimensioneStandard); - } - - crSize = grPhoto.MeasureString(TestoFirma, crFont); - LarghezzaStandard = Conversions.ToInteger(crSize.Width); - if (crSize.Width > Conversions.ToSingle(g.Width)) - { - int Conta = DimensioneStandard; - do - { - if (Conta > 20) - { - Conta -= 5; - } - else - { - Conta -= 1; - } - - if (_Grassetto == true) - { - crFont = new Font(_IlFont, Conta, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, Conta); - } - - crSize = grPhoto.MeasureString(TestoFirma, crFont); - if (crSize.Width < Conversions.ToSingle(g.Width)) - { - LarghezzaStandard = Conversions.ToInteger(crSize.Width); - break; - } - - if (Conta <= 5) - break; - } - while (true); - DimensioneStandard = Conta; - } - - var yPosFromBottom = default(float); - switch (_Posizione.ToUpper() ?? "") - { - case "ALTO": - { - yPosFromBottom = _Margine; - break; - } - - case "BASSO": - { - // yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - // yPosFromBottom = CType((g.Height - DimensioneStandard - (g.Height * _Margine / 100) - (DimensioneStandard * 0.3)), Single) - yPosFromBottom = Conversions.ToSingle(g.Height - crSize.Height - g.Height * _Margine / 100d); - break; - } - } - - var xCenterOfImg = default(float); - var StrFormat = new StringFormat(); - switch (_Allineamento.ToUpper() ?? "") - { - case "SINISTRA": - { - xCenterOfImg = Conversions.ToSingle(_Margine + LarghezzaStandard / 2d); - if (LarghezzaStandard / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - - case "CENTRO": - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - break; - } - - case "DESTRA": - { - xCenterOfImg = Conversions.ToSingle(g.Width - _Margine - LarghezzaStandard / 2d); - if (LarghezzaStandard / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - } - - StrFormat.Alignment = StringAlignment.Center; - var semiTransBrush2 = new SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)); - var semiTransBrush = new SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)); - if (_Grassetto == true) - { - crFont = new Font(_IlFont, DimensioneStandard, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, DimensioneStandard); - } - - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom + 1f), StrFormat); - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), StrFormat); - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileBig2 = NomeFileBig; - NomeFileBig = NomeFileBig.Substring(0, NomeFileBig.Length - 4) + Codice + NomeFileBig.Substring(NomeFileBig.Length - 4); - } - - - // imgOutputBig - if (_LogoAggiungi == true & File.Exists(_LogoNomeFile)) - { - var ImmagineLogo = Image.FromFile(_LogoNomeFile); - var LogoColoreTrasparente = Color.White; - // Dim bmWatermark As Bitmap - - // * Create a Bitmap based on the previously modified photograph Bitmap - // bmWatermark = New Bitmap(imgOutputBig) - // bmWatermark.SetResolution(imgOutputBig.HorizontalResolution, imgOutputBig.VerticalResolution) - - // * Load this Bitmap into a new Graphic Object - var grWatermark = Graphics.FromImage(imgOutputBig); - - // * To achieve a transulcent watermark we will apply (2) color manipulations - var imageAttributes = new System.Drawing.Imaging.ImageAttributes(); - - // * The first step replace the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0) - var colorMap = new System.Drawing.Imaging.ColorMap(); - - // * background this will be the color we search for and replace with transparency - colorMap.OldColor = LogoColoreTrasparente; - colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); - var remapTable = new[] { colorMap }; - imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); - - // * 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, Conversions.ToSingle(_LogoTrasparenza) / 100f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; - var wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); - imageAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); - int FotoLogoH = _LogoAltezza; - int FotoLogoW = _LogoLarghezza; - double FattoreAlt = ImmagineLogo.Height / (double)FotoLogoH; - double FattoreLarg = ImmagineLogo.Width / (double)FotoLogoW; - Size NuovaSize; - if (FattoreLarg > FattoreAlt) - { - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoW, "Larghezza"); - } - else - { - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoH, "Altezza"); - } - - int MargineUsato; - int MargineL; - bool InPercentualeL; - if (_LogoMargine.EndsWith("%") == true) - { - InPercentualeL = true; - } - else - { - InPercentualeL = false; - } - - MargineL = Conversions.ToInteger(Conversion.Val(_LogoMargine)); - if (InPercentualeL == true) - { - MargineUsato = Conversions.ToInteger(imgOutputBig.Height * MargineL / 100d); - } - else - { - MargineUsato = MargineL; - } - - var xPosOfWm = default(int); - var yPosOfWm = default(int); - switch (_LogoPosizioneH.ToUpper() ?? "") - { - case "SINISTRA": - case "NESSUNA": - { - xPosOfWm = MargineUsato; - break; - } - - case "CENTRO": - { - xPosOfWm = Conversions.ToInteger((imgOutputBig.Width - NuovaSize.Width) / 2d); - break; - } - - case "DESTRA": - { - xPosOfWm = imgOutputBig.Width - NuovaSize.Width - MargineUsato; - break; - } - } - - switch (_LogoPosizioneV.ToUpper() ?? "") - { - case "ALTO": - case "NESSUNA": - { - yPosOfWm = MargineUsato; - break; - } - - case "CENTRO": - { - yPosOfWm = Conversions.ToInteger((imgOutputBig.Height - NuovaSize.Height) / 2d); - break; - } - - case "BASSO": - { - yPosOfWm = imgOutputBig.Height - NuovaSize.Height - MargineUsato; - break; - } - } - - grWatermark.DrawImage(ImmagineLogo, new Rectangle(xPosOfWm, yPosOfWm, NuovaSize.Width, NuovaSize.Height), 0, 0, ImmagineLogo.Width, ImmagineLogo.Height, GraphicsUnit.Pixel, imageAttributes); - grWatermark.Dispose(); - } - - if (_FotoGrandeDimOrigina == false) - { - imgOutputBig.Save(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig), thisFormat); - var g2 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - if (g2.Width > g2.Height) - { - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _LarghezzaBig, "Larghezza"); - } - else - { - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _AltezzaBig, "Altezza"); - } - - var imgOutputBig2 = new Bitmap(g2, thumbSizeBig.Width, thumbSizeBig.Height); - imgOutputBig2.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat); - imgOutputBig2.Dispose(); - imgOutputBig.Dispose(); - g2.Dispose(); - } - else - { - imgOutputBig.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat); - imgOutputBig.Dispose(); - } - - if (_CreaMiniature == true) - { - if (_AggiungiScritteMiniature == true) - { - Image g1; - if (_FotoGrandeDimOrigina == false) - { - g1 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - } - else - { - g1 = Image.FromFile(Path.Combine(_DestDir.FullName, NomeFileBig)); - } - - var imgOutputSmall = new Bitmap(g1, thumbSizeSmall.Width, thumbSizeSmall.Height); - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4); - } - - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall.Dispose(); - g1.Dispose(); - } - } - - if (File.Exists(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)) == true) - { - FileSystem.Kill(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - } - - g.Dispose(); - grPhoto.Dispose(); - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - FileSystem.Kill(Path.Combine(_SourceDir.FullName, NomeFileBig2)); - } - } - - public Size NewthumbSize(int currentwidth, int currentheight, int MaxPixel, string TipoSize) - { - // Calculate the Size of the New image - // *** Larghezza, Altezza, Auto - - double tempMultiplier; - if ((TipoSize.ToUpper() ?? "") == ("Larghezza".ToUpper() ?? "")) - { - tempMultiplier = MaxPixel / (double)currentwidth; - } - else if ((TipoSize.ToUpper() ?? "") == ("Altezza".ToUpper() ?? "")) - { - tempMultiplier = MaxPixel / (double)currentheight; - } - else if (currentheight > currentwidth) // portrait - { - tempMultiplier = MaxPixel / (double)currentheight; - } - else - { - tempMultiplier = MaxPixel / (double)currentwidth; - } - - var NewSize = new Size((int)Math.Round(currentwidth * tempMultiplier), (int)Math.Round(currentheight * tempMultiplier)); - return NewSize; - } - - public string DirectorySorgente - { - get - { - return _DirectorySorgente; - } - - set - { - _DirectorySorgente = value; - } - } - - public string DirectoryDestinazione - { - get - { - return _DirectoryDestinazione; - } - - set - { - _DirectoryDestinazione = value; - } - } - - public DirectoryInfo SourceDir - { - get - { - return _SourceDir; - } - - set - { - _SourceDir = value; - } - } - - public DirectoryInfo DestDirStart - { - get - { - return _DestDirStart; - } - - set - { - _DestDirStart = value; - } - } - - public string TestoFirmaStart - { - get - { - return _TestoFirmaStart; - } - - set - { - _TestoFirmaStart = value; - } - } - - public string TestoFirmaStartV - { - get - { - return _TestoFirmaStartV; - } - - set - { - _TestoFirmaStartV = value; - } - } - - public DateTime DataPartenza - { - get - { - return _DataPartenza; - } - - set - { - _DataPartenza = value; - } - } - - public string TestoOrario - { - get - { - return _TestoOrario; - } - - set - { - _TestoOrario = value; - } - } - - public int DimStandard - { - get - { - return _DimStandard; - } - - set - { - _DimStandard = value; - } - } - - public int DimStandardMiniatura - { - get - { - return _DimStandardMiniatura; - } - - set - { - _DimStandardMiniatura = value; - } - } - - public bool UsaOrarioMiniatura - { - get - { - return _UsaOrarioMiniatura; - } - - set - { - _UsaOrarioMiniatura = value; - } - } - - public bool UsaOrarioTestoApplicare - { - get - { - return _UsaOrarioTestoApplicare; - } - - set - { - _UsaOrarioTestoApplicare = value; - } - } - - public bool UsaTempoGaraTestoApplicare - { - get - { - return _UsaTempoGaraTestoApplicare; - } - - set - { - _UsaTempoGaraTestoApplicare = value; - } - } - - public bool UsaRotazioneAutomatica - { - get - { - return _UsaRotazioneAutomatica; - } - - set - { - _UsaRotazioneAutomatica = value; - } - } - - public bool UsaForzaJpg - { - get - { - return _UsaForzaJpg; - } - - set - { - _UsaForzaJpg = value; - } - } - - public int LarghezzaSmall - { - get - { - return _LarghezzaSmall; - } - - set - { - _LarghezzaSmall = value; - } - } - - public int AltezzaSmall - { - get - { - return _AltezzaSmall; - } - - set - { - _AltezzaSmall = value; - } - } - - public bool CreaMiniature - { - get - { - return _CreaMiniature; - } - - set - { - _CreaMiniature = value; - } - } - - public bool AggiungiScritteMiniature - { - get - { - return _AggiungiScritteMiniature; - } - - set - { - _AggiungiScritteMiniature = value; - } - } - - public string NomeFileChild - { - get - { - return _NomeFileChild; - } - - set - { - _NomeFileChild = value; - } - } - - public string Suffisso - { - get - { - return _Suffisso; - } - - set - { - _Suffisso = value; - } - } - - public string Codice - { - get - { - return _Codice; - } - - set - { - _Codice = value; - } - } - - public int Trasparenza - { - get - { - return _Trasparenza; - } - - set - { - _Trasparenza = value; - } - } - - public string IlFont - { - get - { - return _IlFont; - } - - set - { - _IlFont = value; - } - } - - public bool Grassetto - { - get - { - return _Grassetto; - } - - set - { - _Grassetto = value; - } - } - - public string Posizione - { - get - { - return _Posizione; - } - - set - { - _Posizione = value; - } - } - - public string Allineamento - { - get - { - return _Allineamento; - } - - set - { - _Allineamento = value; - } - } - - public int Margine - { - get - { - return _Margine; - } - - set - { - _Margine = value; - } - } - - public int LogoAltezza - { - get - { - return _LogoAltezza; - } - - set - { - _LogoAltezza = value; - } - } - - public int LogoLarghezza - { - get - { - return _LogoLarghezza; - } - - set - { - _LogoLarghezza = value; - } - } - - public int FontColoreR - { - get - { - return _FontColoreR; - } - - set - { - _FontColoreR = value; - } - } - - public int FontColoreG - { - get - { - return _FontColoreG; - } - - set - { - _FontColoreG = value; - } - } - - public int FontColoreB - { - get - { - return _FontColoreB; - } - - set - { - _FontColoreB = value; - } - } - - public bool LogoAggiungi - { - get - { - return _LogoAggiungi; - } - - set - { - _LogoAggiungi = value; - } - } - - public string LogoNomeFile - { - get - { - return _LogoNomeFile; - } - - set - { - _LogoNomeFile = value; - } - } - - public string LogoTrasparenza - { - get - { - return _LogoTrasparenza; - } - - set - { - _LogoTrasparenza = value; - } - } - - public string LogoMargine - { - get - { - return _LogoMargine; - } - - set - { - _LogoMargine = value; - } - } - - public string LogoPosizioneH - { - get - { - return _LogoPosizioneH; - } - - set - { - _LogoPosizioneH = value; - } - } - - public string LogoPosizioneV - { - get - { - return _LogoPosizioneV; - } - - set - { - _LogoPosizioneV = value; - } - } - - public bool FotoGrandeDimOrigina - { - get - { - return _FotoGrandeDimOrigina; - } - - set - { - _FotoGrandeDimOrigina = value; - } - } - - public int AltezzaBig - { - get - { - return _AltezzaBig; - } - - set - { - _AltezzaBig = value; - } - } - - public int LarghezzaBig - { - get - { - return _LarghezzaBig; - } - - set - { - _LarghezzaBig = value; - } - } - - public DirectoryInfo DestDir - { - get - { - return _DestDir; - } - - set - { - _DestDir = value; - } - } - } -} \ No newline at end of file diff --git a/imagecatalog/CreaImmagineSeparateMultiCore.vb b/imagecatalog/CreaImmagineSeparateMultiCore.vb deleted file mode 100644 index 4b645f8..0000000 --- a/imagecatalog/CreaImmagineSeparateMultiCore.vb +++ /dev/null @@ -1,943 +0,0 @@ -Imports System.IO -'Imports System.Drawing.Drawing2D -'Imports System.Drawing.Imaging -'Imports System.Threading - -Public Class CreaImmagineSeparateMultiCore - - Private _DirectorySorgente As String - Private _DirectoryDestinazione As String - - - Private _SourceDir As DirectoryInfo - Private _DestDirStart As DirectoryInfo - Private _DimStandard As Integer - Private _DimStandardMiniatura As Integer - - - Private _UsaOrarioMiniatura As Boolean - Private _UsaOrarioTestoApplicare As Boolean - Private _UsaTempoGaraTestoApplicare As Boolean - Private _TestoFirmaStart As String - Private _TestoFirmaStartV As String - Private _DataPartenza As DateTime - Private _TestoOrario As String - - Private _UsaRotazioneAutomatica As Boolean - Private _UsaForzaJpg As Boolean - - Private _LarghezzaSmall As Integer - Private _AltezzaSmall As Integer - - Private _CreaMiniature As Boolean - Private _AggiungiScritteMiniature As Boolean - - Private _NomeFileChild As String - Private _Suffisso As String - Private _Codice As String - - Private _Trasparenza As Integer - Private _IlFont As String - Private _Grassetto As Boolean - - Private _Posizione As String - Private _Allineamento As String - Private _Margine As Integer - - Private _LogoAltezza As Integer - Private _LogoLarghezza As Integer - - Private _FontColoreR As Integer - Private _FontColoreG As Integer - Private _FontColoreB As Integer - - Private _LogoAggiungi As Boolean - Private _LogoNomeFile As String - Private _LogoTrasparenza As String - Private _LogoMargine As String - Private _LogoPosizioneH As String - Private _LogoPosizioneV As String - - Private _FotoGrandeDimOrigina As Boolean - Private _AltezzaBig As Integer - Private _LarghezzaBig As Integer - Private _DestDir As DirectoryInfo - - Public Sub CreaImmagine(ByVal InfoImg As PicInfo) - Dim TestoFirma As String = "" - - _DestDir = InfoImg.DirDest - _SourceDir = InfoImg.DirSource - _DestDirStart = InfoImg.DirDestStart - _NomeFileChild = InfoImg.NomeImmagine - - Dim AlphaScelta As Integer = CType((255 * (100 - _Trasparenza) / 100), Integer) - - Dim DimensioneStandard As Integer - Dim DimensioneStandardMiniatura As Integer - - Dim DataFoto As DateTime - Dim DataPartenzaI As DateTime = _DataPartenza - If _TestoOrario.Length > 0 Then - _TestoOrario &= " " - End If - Dim TestoFirmaPiccola As String = "" - - Dim FileConta As Integer = 0 - Dim ContaFileXDir As Integer = 0 - Dim ContaDirXDir As Integer = 0 - Dim TestoTemp As String = "" - Dim ContaTemp As Integer = 0 - - DimensioneStandard = _DimStandard - DimensioneStandardMiniatura = _DimStandardMiniatura - - Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_SourceDir.FullName, _NomeFileChild)) - - If _UsaOrarioTestoApplicare = True Or _UsaTempoGaraTestoApplicare = True Or _UsaOrarioMiniatura = True Then - If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - Dim DatiExif As New ExifReader(CType(g, Bitmap)) - DataFoto = DatiExif.DateTimeOriginal - TestoFirma = _TestoFirmaStart - If DataFoto.Year <> 1 Then - TestoFirmaPiccola = DataFoto.ToShortTimeString - If _UsaOrarioTestoApplicare = True Then - TestoFirma &= " - " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - End If - If _UsaTempoGaraTestoApplicare = True Then - Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - TestoFirma &= " - " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - End If - End If - End If - Else - TestoFirma = _TestoFirmaStart - End If - - Dim FotoRuotaADestra As Boolean = False - Dim FotoRuotaASinistra As Boolean = False - - If _UsaRotazioneAutomatica = True Then - If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - Dim DatiExif As New ExifReader(CType(g, Bitmap)) - - Select Case DatiExif.Orientation - Case ExifReader.Orientations.BottomLeft - - Case ExifReader.Orientations.BottomRight - - Case ExifReader.Orientations.LeftTop - - Case ExifReader.Orientations.LftBottom - FotoRuotaASinistra = True - Case ExifReader.Orientations.RightBottom - - Case ExifReader.Orientations.RightTop - - Case ExifReader.Orientations.TopLeft - - Case ExifReader.Orientations.TopRight - - End Select - End If - End If - 'rotazione - If FotoRuotaASinistra = True Then - g.RotateFlip(RotateFlipType.Rotate270FlipNone) - End If - If FotoRuotaADestra = True Then - g.RotateFlip(RotateFlipType.Rotate90FlipNone) - End If - - Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat - If _UsaForzaJpg = True Then - thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg - End If - - Dim thumbSizeSmall As New Size - Dim thumbSizeBig As New Size - Dim NomeFileSmall As String = "" - Dim NomeFileBig As String = "" - Dim NomeFileBig2 As String = "" - - If g.Width > g.Height Then - thumbSizeSmall = NewthumbSize(g.Width, g.Height, LarghezzaSmall, "Larghezza") - Dim SizeOrig As New Size(g.Width, g.Height) - thumbSizeBig = SizeOrig - Else - thumbSizeSmall = NewthumbSize(g.Width, g.Height, AltezzaSmall, "Altezza") - Dim SizeOrig As New Size(g.Width, g.Height) - thumbSizeBig = SizeOrig - End If - - NomeFileSmall = Suffisso & _NomeFileChild - NomeFileBig = _NomeFileChild - - Dim imgOutputBig As New Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height) - imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution) - - If _CreaMiniature = True Then - If _AggiungiScritteMiniature = False Then - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) & Codice & NomeFileSmall.Substring(NomeFileSmall.Length - 4) - End If - If _UsaOrarioMiniatura = True Then - If TestoFirmaPiccola.Length > 0 Then - Dim imgOutputSmall As Bitmap - imgOutputSmall = CType(imgOutputBig.Clone, Bitmap) - - Dim grPhoto1 As Graphics - grPhoto1 = Graphics.FromImage(imgOutputSmall) - grPhoto1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias - - Dim crFont1 As Font = Nothing - Dim crSize1 As SizeF = New SizeF - Dim LarghezzaStandard1 As Integer - - If _Grassetto = True Then - crFont1 = New Font(IlFont, DimensioneStandardMiniatura, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura) - End If - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1) - LarghezzaStandard1 = CType(crSize1.Width, Integer) - - If crSize1.Width > CType(g.Width, Single) Then - Dim Conta As Integer = DimensioneStandardMiniatura - Do - If Conta > 20 Then - Conta -= 5 - Else - Conta -= 1 - End If - If _Grassetto = True Then - crFont1 = New Font(_IlFont, Conta, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, Conta) - End If - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1) - If crSize1.Width < CType(g.Width, Single) Then - LarghezzaStandard1 = CType(crSize1.Width, Integer) - Exit Do - End If - If Conta <= 5 Then Exit Do - Loop - DimensioneStandardMiniatura = Conta - End If - - Dim yPosFromBottom1 As Single - Select Case _Posizione.ToUpper - Case "ALTO" - yPosFromBottom1 = (_Margine) - - Case "BASSO" - 'yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - 'yPosFromBottom1 = CType((g.Height - crFont1.Height - (g.Height * _Margine / 100) - (crFont1.Height * 0.3)), Single) - yPosFromBottom1 = CType((g.Height - crSize1.Height - (g.Height * _Margine / 100)), Single) - - End Select - - Dim xCenterOfImg1 As Single - Dim StrFormat1 As StringFormat = New StringFormat - Select Case _Allineamento.ToUpper - Case "SINISTRA" - xCenterOfImg1 = CType((_Margine + (LarghezzaStandard1 / 2)), Single) - If (LarghezzaStandard1 / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg1 = CType((g.Width / 2), Single) - End If - - Case "CENTRO" - xCenterOfImg1 = CType((g.Width / 2), Single) - - Case "DESTRA" - xCenterOfImg1 = CType((g.Width - _Margine - (LarghezzaStandard1 / 2)), Single) - If (LarghezzaStandard1 / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg1 = CType((g.Width / 2), Single) - End If - - End Select - StrFormat1.Alignment = StringAlignment.Center - - Dim semiTransBrush21 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)) - Dim semiTransBrush1 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)) - - If _Grassetto = True Then - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura) - End If - - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush21, New PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1) - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush1, New PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1) - - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall), thisFormat) - Dim g2 As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall)) - Dim imgOutputSmall2 As New Bitmap(g2, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall2.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - - imgOutputSmall2.Dispose() - imgOutputSmall.Dispose() - g2.Dispose() - Kill(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall)) - Else - Dim imgOutputSmall As New Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - imgOutputSmall.Dispose() - End If - Else - Dim imgOutputSmall As New Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - imgOutputSmall.Dispose() - End If - End If - End If - - Dim grPhoto As Graphics - grPhoto = Graphics.FromImage(imgOutputBig) - grPhoto.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias - - Dim crFont As Font = Nothing - Dim crSize As SizeF = New SizeF - Dim LarghezzaStandard As Integer - - If _Grassetto = True Then - crFont = New Font(_IlFont, DimensioneStandard, FontStyle.Bold) - Else - crFont = New Font(_IlFont, DimensioneStandard) - End If - crSize = grPhoto.MeasureString(TestoFirma, crFont) - LarghezzaStandard = CType(crSize.Width, Integer) - - If crSize.Width > CType(g.Width, Single) Then - Dim Conta As Integer = DimensioneStandard - Do - If Conta > 20 Then - Conta -= 5 - Else - Conta -= 1 - End If - If _Grassetto = True Then - crFont = New Font(_IlFont, Conta, FontStyle.Bold) - Else - crFont = New Font(_IlFont, Conta) - End If - crSize = grPhoto.MeasureString(TestoFirma, crFont) - If crSize.Width < CType(g.Width, Single) Then - LarghezzaStandard = CType(crSize.Width, Integer) - Exit Do - End If - If Conta <= 5 Then Exit Do - Loop - DimensioneStandard = Conta - End If - - Dim yPosFromBottom As Single - Select Case _Posizione.ToUpper - Case "ALTO" - yPosFromBottom = (_Margine) - - Case "BASSO" - 'yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - 'yPosFromBottom = CType((g.Height - DimensioneStandard - (g.Height * _Margine / 100) - (DimensioneStandard * 0.3)), Single) - yPosFromBottom = CType((g.Height - crSize.Height - (g.Height * _Margine / 100)), Single) - End Select - - Dim xCenterOfImg As Single - Dim StrFormat As StringFormat = New StringFormat - Select Case _Allineamento.ToUpper - Case "SINISTRA" - xCenterOfImg = CType((_Margine + (LarghezzaStandard / 2)), Single) - If (LarghezzaStandard / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg = CType((g.Width / 2), Single) - End If - - Case "CENTRO" - xCenterOfImg = CType((g.Width / 2), Single) - - Case "DESTRA" - xCenterOfImg = CType((g.Width - _Margine - (LarghezzaStandard / 2)), Single) - If (LarghezzaStandard / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg = CType((g.Width / 2), Single) - End If - - End Select - StrFormat.Alignment = StringAlignment.Center - - Dim semiTransBrush2 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)) - Dim semiTransBrush As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)) - - If _Grassetto = True Then - crFont = New Font(_IlFont, DimensioneStandard, FontStyle.Bold) - Else - crFont = New Font(_IlFont, DimensioneStandard) - End If - - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat) - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom), StrFormat) - - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileBig2 = NomeFileBig - NomeFileBig = NomeFileBig.Substring(0, NomeFileBig.Length - 4) & Codice & NomeFileBig.Substring(NomeFileBig.Length - 4) - End If - - - 'imgOutputBig - If _LogoAggiungi = True And File.Exists(_LogoNomeFile) Then - - Dim ImmagineLogo As Image = Image.FromFile(_LogoNomeFile) - - Dim LogoColoreTrasparente As Color = Color.White - 'Dim bmWatermark As Bitmap - - '* Create a Bitmap based on the previously modified photograph Bitmap - 'bmWatermark = New Bitmap(imgOutputBig) - 'bmWatermark.SetResolution(imgOutputBig.HorizontalResolution, imgOutputBig.VerticalResolution) - - '* Load this Bitmap into a new Graphic Object - Dim grWatermark As Graphics = Graphics.FromImage(imgOutputBig) - - '* To achieve a transulcent watermark we will apply (2) color manipulations - Dim imageAttributes As Imaging.ImageAttributes = New Imaging.ImageAttributes - - '* The first step replace the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0) - Dim colorMap As Imaging.ColorMap = New Imaging.ColorMap - - '* background this will be the color we search for and replace with transparency - colorMap.OldColor = LogoColoreTrasparente - colorMap.NewColor = Color.FromArgb(0, 0, 0, 0) - - Dim remapTable As Imaging.ColorMap() = {colorMap} - imageAttributes.SetRemapTable(remapTable, Imaging.ColorAdjustType.Bitmap) - - '* The second color manipulation is used to change the opacity by setting the 3rd row and 3rd column to 0.3f - Dim colorMatrixElements As Single()() = {New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, CType(_LogoTrasparenza, Single) / 100, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}} - Dim wmColorMatrix As Imaging.ColorMatrix = New Imaging.ColorMatrix(colorMatrixElements) - imageAttributes.SetColorMatrix(wmColorMatrix, Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Bitmap) - - Dim FotoLogoH As Integer = _LogoAltezza - Dim FotoLogoW As Integer = _LogoLarghezza - Dim FattoreAlt As Double = ImmagineLogo.Height / FotoLogoH - Dim FattoreLarg As Double = ImmagineLogo.Width / FotoLogoW - Dim NuovaSize As Size - If FattoreLarg > FattoreAlt Then - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoW, "Larghezza") - Else - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoH, "Altezza") - End If - - Dim MargineUsato As Integer - Dim MargineL As Integer - Dim InPercentualeL As Boolean - If _LogoMargine.EndsWith("%") = True Then - InPercentualeL = True - Else - InPercentualeL = False - End If - MargineL = CType(Val(_LogoMargine), Integer) - If InPercentualeL = True Then - MargineUsato = CType(imgOutputBig.Height * MargineL / 100, Integer) - Else - MargineUsato = MargineL - End If - - Dim xPosOfWm As Integer - Dim yPosOfWm As Integer - Select Case _LogoPosizioneH.ToUpper - Case "SINISTRA", "NESSUNA" - xPosOfWm = MargineUsato - - Case "CENTRO" - xPosOfWm = CType((imgOutputBig.Width - NuovaSize.Width) / 2, Integer) - - Case "DESTRA" - xPosOfWm = ((imgOutputBig.Width - NuovaSize.Width) - MargineUsato) - End Select - Select Case _LogoPosizioneV.ToUpper - Case "ALTO", "NESSUNA" - yPosOfWm = MargineUsato - - Case "CENTRO" - yPosOfWm = CType((imgOutputBig.Height - NuovaSize.Height) / 2, Integer) - - Case "BASSO" - yPosOfWm = ((imgOutputBig.Height - NuovaSize.Height) - MargineUsato) - End Select - - grWatermark.DrawImage(ImmagineLogo, New Rectangle(xPosOfWm, yPosOfWm, NuovaSize.Width, NuovaSize.Height), 0, 0, ImmagineLogo.Width, ImmagineLogo.Height, GraphicsUnit.Pixel, imageAttributes) - grWatermark.Dispose() - End If - - If _FotoGrandeDimOrigina = False Then - imgOutputBig.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig), thisFormat) - Dim g2 As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - If g2.Width > g2.Height Then - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _LarghezzaBig, "Larghezza") - Else - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _AltezzaBig, "Altezza") - End If - Dim imgOutputBig2 As New Bitmap(g2, thumbSizeBig.Width, thumbSizeBig.Height) - imgOutputBig2.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - imgOutputBig2.Dispose() - imgOutputBig.Dispose() - g2.Dispose() - Else - imgOutputBig.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - imgOutputBig.Dispose() - End If - - If _CreaMiniature = True Then - If _AggiungiScritteMiniature = True Then - Dim g1 As System.Drawing.Image - If _FotoGrandeDimOrigina = False Then - g1 = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - Else - g1 = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, NomeFileBig)) - End If - Dim imgOutputSmall As New Bitmap(g1, thumbSizeSmall.Width, thumbSizeSmall.Height) - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) & Codice & NomeFileSmall.Substring(NomeFileSmall.Length - 4) - End If - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - imgOutputSmall.Dispose() - g1.Dispose() - End If - End If - - If File.Exists(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) = True Then - Kill(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - End If - - g.Dispose() - grPhoto.Dispose() - - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - Kill(Path.Combine(_SourceDir.FullName, NomeFileBig2)) - End If - - End Sub - - - - Function NewthumbSize(ByVal currentwidth As Integer, ByVal currentheight As Integer, ByVal MaxPixel As Integer, ByVal TipoSize As String) As Size - ' Calculate the Size of the New image - '*** Larghezza, Altezza, Auto - - Dim tempMultiplier As Double - - If TipoSize.ToUpper = "Larghezza".ToUpper Then - tempMultiplier = MaxPixel / currentwidth - ElseIf TipoSize.ToUpper = "Altezza".ToUpper Then - tempMultiplier = MaxPixel / currentheight - Else - If currentheight > currentwidth Then ' portrait - tempMultiplier = MaxPixel / currentheight - Else - tempMultiplier = MaxPixel / currentwidth - End If - End If - - Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier)) - - Return NewSize - End Function - - - - - Public Property DirectorySorgente() As String - Get - Return _DirectorySorgente - End Get - Set(ByVal value As String) - _DirectorySorgente = value - End Set - End Property - - Public Property DirectoryDestinazione() As String - Get - Return _DirectoryDestinazione - End Get - Set(ByVal value As String) - _DirectoryDestinazione = value - End Set - End Property - - - Public Property SourceDir() As DirectoryInfo - Get - Return _SourceDir - End Get - Set(ByVal value As DirectoryInfo) - _SourceDir = value - End Set - End Property - - Public Property DestDirStart() As DirectoryInfo - Get - Return _DestDirStart - End Get - Set(ByVal value As DirectoryInfo) - _DestDirStart = value - End Set - End Property - - - - Public Property TestoFirmaStart() As String - Get - Return _TestoFirmaStart - End Get - Set(ByVal value As String) - _TestoFirmaStart = value - End Set - End Property - Public Property TestoFirmaStartV() As String - Get - Return _TestoFirmaStartV - End Get - Set(ByVal value As String) - _TestoFirmaStartV = value - End Set - End Property - - Public Property DataPartenza() As DateTime - Get - Return _DataPartenza - End Get - Set(ByVal value As DateTime) - _DataPartenza = value - End Set - End Property - - Public Property TestoOrario() As String - Get - Return _TestoOrario - End Get - Set(ByVal value As String) - _TestoOrario = value - End Set - End Property - - Public Property DimStandard() As Integer - Get - Return _DimStandard - End Get - Set(ByVal value As Integer) - _DimStandard = value - End Set - End Property - - Public Property DimStandardMiniatura() As Integer - Get - Return _DimStandardMiniatura - End Get - Set(ByVal value As Integer) - _DimStandardMiniatura = value - End Set - End Property - - Public Property UsaOrarioMiniatura() As Boolean - Get - Return _UsaOrarioMiniatura - End Get - Set(ByVal value As Boolean) - _UsaOrarioMiniatura = value - End Set - End Property - - Public Property UsaOrarioTestoApplicare() As Boolean - Get - Return _UsaOrarioTestoApplicare - End Get - Set(ByVal value As Boolean) - _UsaOrarioTestoApplicare = value - End Set - End Property - - Public Property UsaTempoGaraTestoApplicare() As Boolean - Get - Return _UsaTempoGaraTestoApplicare - End Get - Set(ByVal value As Boolean) - _UsaTempoGaraTestoApplicare = value - End Set - End Property - - Public Property UsaRotazioneAutomatica() As Boolean - Get - Return _UsaRotazioneAutomatica - End Get - Set(ByVal value As Boolean) - _UsaRotazioneAutomatica = value - End Set - End Property - - Public Property UsaForzaJpg() As Boolean - Get - Return _UsaForzaJpg - End Get - Set(ByVal value As Boolean) - _UsaForzaJpg = value - End Set - End Property - - - - Public Property LarghezzaSmall() As Integer - Get - Return _LarghezzaSmall - End Get - Set(ByVal value As Integer) - _LarghezzaSmall = value - End Set - End Property - - Public Property AltezzaSmall() As Integer - Get - Return _AltezzaSmall - End Get - Set(ByVal value As Integer) - _AltezzaSmall = value - End Set - End Property - - - Public Property CreaMiniature() As Boolean - Get - Return _CreaMiniature - End Get - Set(ByVal value As Boolean) - _CreaMiniature = value - End Set - End Property - - Public Property AggiungiScritteMiniature() As Boolean - Get - Return _AggiungiScritteMiniature - End Get - Set(ByVal value As Boolean) - _AggiungiScritteMiniature = value - End Set - End Property - - Public Property NomeFileChild() As String - Get - Return _NomeFileChild - End Get - Set(ByVal value As String) - _NomeFileChild = value - End Set - End Property - - Public Property Suffisso() As String - Get - Return _Suffisso - End Get - Set(ByVal value As String) - _Suffisso = value - End Set - End Property - - Public Property Codice() As String - Get - Return _Codice - End Get - Set(ByVal value As String) - _Codice = value - End Set - End Property - - - Public Property Trasparenza() As Integer - Get - Return _Trasparenza - End Get - Set(ByVal value As Integer) - _Trasparenza = value - End Set - End Property - - Public Property IlFont() As String - Get - Return _IlFont - End Get - Set(ByVal value As String) - _IlFont = value - End Set - End Property - - Public Property Grassetto() As Boolean - Get - Return _Grassetto - End Get - Set(ByVal value As Boolean) - _Grassetto = value - End Set - End Property - - Public Property Posizione() As String - Get - Return _Posizione - End Get - Set(ByVal value As String) - _Posizione = value - End Set - End Property - - Public Property Allineamento() As String - Get - Return _Allineamento - End Get - Set(ByVal value As String) - _Allineamento = value - End Set - End Property - - Public Property Margine() As Integer - Get - Return _Margine - End Get - Set(ByVal value As Integer) - _Margine = value - End Set - End Property - - Public Property LogoAltezza() As Integer - Get - Return _LogoAltezza - End Get - Set(ByVal value As Integer) - _LogoAltezza = value - End Set - End Property - - Public Property LogoLarghezza() As Integer - Get - Return _LogoLarghezza - End Get - Set(ByVal value As Integer) - _LogoLarghezza = value - End Set - End Property - - Public Property FontColoreR() As Integer - Get - Return _FontColoreR - End Get - Set(ByVal value As Integer) - _FontColoreR = value - End Set - End Property - - Public Property FontColoreG() As Integer - Get - Return _FontColoreG - End Get - Set(ByVal value As Integer) - _FontColoreG = value - End Set - End Property - - Public Property FontColoreB() As Integer - Get - Return _FontColoreB - End Get - Set(ByVal value As Integer) - _FontColoreB = value - End Set - End Property - - Public Property LogoAggiungi() As Boolean - Get - Return _LogoAggiungi - End Get - Set(ByVal value As Boolean) - _LogoAggiungi = value - End Set - End Property - - Public Property LogoNomeFile() As String - Get - Return _LogoNomeFile - End Get - Set(ByVal value As String) - _LogoNomeFile = value - End Set - End Property - - Public Property LogoTrasparenza() As String - Get - Return _LogoTrasparenza - End Get - Set(ByVal value As String) - _LogoTrasparenza = value - End Set - End Property - - Public Property LogoMargine() As String - Get - Return _LogoMargine - End Get - Set(ByVal value As String) - _LogoMargine = value - End Set - End Property - - Public Property LogoPosizioneH() As String - Get - Return _LogoPosizioneH - End Get - Set(ByVal value As String) - _LogoPosizioneH = value - End Set - End Property - - Public Property LogoPosizioneV() As String - Get - Return _LogoPosizioneV - End Get - Set(ByVal value As String) - _LogoPosizioneV = value - End Set - End Property - - Public Property FotoGrandeDimOrigina() As Boolean - Get - Return _FotoGrandeDimOrigina - End Get - Set(ByVal value As Boolean) - _FotoGrandeDimOrigina = value - End Set - End Property - - Public Property AltezzaBig() As Integer - Get - Return _AltezzaBig - End Get - Set(ByVal value As Integer) - _AltezzaBig = value - End Set - End Property - - Public Property LarghezzaBig() As Integer - Get - Return _LarghezzaBig - End Get - Set(ByVal value As Integer) - _LarghezzaBig = value - End Set - End Property - - Public Property DestDir() As DirectoryInfo - Get - Return _DestDir - End Get - Set(ByVal value As DirectoryInfo) - _DestDir = value - End Set - End Property - - - -End Class diff --git a/imagecatalog/CreaImmagineSeparateThread.cs b/imagecatalog/CreaImmagineSeparateThread.cs deleted file mode 100644 index cf80e50..0000000 --- a/imagecatalog/CreaImmagineSeparateThread.cs +++ /dev/null @@ -1,1721 +0,0 @@ -using System; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.IO; -using Microsoft.VisualBasic; -using Microsoft.VisualBasic.CompilerServices; - -namespace ImageCatalog -{ - // Imports System.Threading - - public class CreaImmagineSeparateThread - { - /* TODO ERROR: Skipped RegionDirectiveTrivia */ - private string _DirectorySorgente; - private string _DirectoryDestinazione; - private int _DimVert; - private int _MargVert; - private DirectoryInfo _SourceDir; - private DirectoryInfo _DestDirStart; - private int _DimStandard; - private int _DimStandardMiniatura; - private bool _NomeData; - private bool _TestoNome; - private bool _UsaOrarioMiniatura; - private bool _UsaOrarioTestoApplicare; - private bool _UsaTempoGaraTestoApplicare; - private string _TestoFirmaStart; - private string _TestoFirmaStartV; - private DateTime _DataPartenza; - private string _TestoOrario; - private bool _UsaRotazioneAutomatica; - private bool _UsaForzaJpg; - private int _LarghezzaSmall; - private int _AltezzaSmall; - private bool _CreaMiniature; - private bool _AggiungiScritteMiniature; - private bool _AggTempoGaraMin; - private bool _AggNumTempMin; - private string _NomeFileChild; - private string _Suffisso; - private string _Codice; - private int _Trasparenza; - private string _IlFont; - private bool _Grassetto; - private string _Posizione; - private string _Allineamento; - private int _Margine; - private int _LogoAltezza; - private int _LogoLarghezza; - private int _FontColoreR; - private int _FontColoreG; - private int _FontColoreB; - private Color _fontColoreRGB; - private bool _LogoAggiungi; - private string _LogoNomeFile; - private string _LogoTrasparenza; - private string _LogoMargine; - private string _LogoPosizioneH; - private string _LogoPosizioneV; - private bool _FotoGrandeDimOrigina; - private int _AltezzaBig; - private int _LarghezzaBig; - private DirectoryInfo _DestDir; - private int _DimMin; - private bool _TestoMin; - private bool _SecretDefault; - private bool _SecretBig; - private bool _SecretSmall; - private string _SecretPathSmall; - private string _SecretPathBig; - private long _jpegQuality; - private long _jpegQualityMin; - private bool FotoRuotaADestra = false; - private bool FotoRuotaASinistra = false; - private string TempMinText = ""; - // Private crFont1 As Font - - - /* TODO ERROR: Skipped EndRegionDirectiveTrivia */ - private void ProcA(ref Image g, ref DateTime DataFoto, ref string TestoFirma, ref string TestoFirmaV, ref string TestoFirmaPiccola, ref DateTime DataPartenzaI) - { - if (g.PropertyIdList.Length > 0) // ci sono dati exif - { - var DatiExif = new ExifReader((Bitmap)g); - DataFoto = DatiExif.DateTimeOriginal; - TestoFirma = _TestoFirmaStart; - TestoFirmaV = _TestoFirmaStartV; - if (DataFoto.Year != 1) - { - TestoFirmaPiccola = DataFoto.ToShortTimeString(); - if (_UsaOrarioTestoApplicare == true) - { - TestoFirma += " " + DataFoto.ToShortDateString() + " " + DataFoto.ToLongTimeString(); - TestoFirmaV += " " + DataFoto.ToShortDateString() + " " + DataFoto.ToLongTimeString(); - } - - if (_UsaTempoGaraTestoApplicare == true) - { - var Orario = new TimeSpan(DateAndTime.DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000L); - TestoFirma += " " + _TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00"); - TestoFirmaV += " " + _TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00"); - } - } - } - } - - private void Rotation(ref Image g) - { - FotoRuotaADestra = false; - FotoRuotaASinistra = false; - if (_UsaRotazioneAutomatica == true) - { - if (g.PropertyIdList.Length > 0) // ci sono dati exif - { - var DatiExif = new ExifReader((Bitmap)g); - switch (DatiExif.Orientation) - { - case ExifReader.Orientations.BottomLeft: - { - break; - } - - case ExifReader.Orientations.BottomRight: - { - break; - } - - case ExifReader.Orientations.LeftTop: - { - break; - } - - case ExifReader.Orientations.LftBottom: - { - FotoRuotaASinistra = true; - break; - } - - case ExifReader.Orientations.RightBottom: - { - break; - } - - case ExifReader.Orientations.RightTop: - { - break; - } - - case ExifReader.Orientations.TopLeft: - { - break; - } - - case ExifReader.Orientations.TopRight: - { - break; - } - } - } - } - - if (FotoRuotaASinistra == true) - { - g.RotateFlip(RotateFlipType.Rotate270FlipNone); - } - - if (FotoRuotaADestra == true) - { - g.RotateFlip(RotateFlipType.Rotate90FlipNone); - } - } - - public void CreaImmagineThread(string Info) - { - string TestoFirma = ""; - string TestoFirmaV = ""; - int AlphaScelta = Conversions.ToInteger(255 * (100 - _Trasparenza) / 100d); - int DimensioneStandard; - int DimensioneStandardMiniatura; - var DataFoto = default(DateTime); - var DataPartenzaI = _DataPartenza; - if (_TestoOrario.Length > 0) - { - _TestoOrario += " "; - } - - string TestoFirmaPiccola = ""; - int FileConta = 0; - int ContaFileXDir = 0; - int ContaDirXDir = 0; - string TestoTemp = ""; - int ContaTemp = 0; - DimensioneStandard = _DimStandard; - DimensioneStandardMiniatura = _DimStandardMiniatura; - var g = Image.FromFile(Path.Combine(_SourceDir.FullName, _NomeFileChild)); - // dati extra in fondo - if (_UsaOrarioTestoApplicare | _UsaTempoGaraTestoApplicare | _UsaOrarioMiniatura | _TestoMin | _AggTempoGaraMin | _AggNumTempMin) - { - ProcA(ref g, ref DataFoto, ref TestoFirma, ref TestoFirmaV, ref TestoFirmaPiccola, ref DataPartenzaI); - } - - // If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - // Dim DatiExif As New ExifReader(CType(g, Bitmap)) - // DataFoto = DatiExif.DateTimeOriginal - // TestoFirma = _TestoFirmaStart - // TestoFirmaV = _TestoFirmaStartV - - // If DataFoto.Year <> 1 Then - // TestoFirmaPiccola = DataFoto.ToShortTimeString - // If _UsaOrarioTestoApplicare = True Then - // TestoFirma &= " - " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - // TestoFirmaV &= " - " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - // End If - // If _UsaTempoGaraTestoApplicare = True Then - // Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - // TestoFirma &= " - " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - // TestoFirmaV &= " - " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - // End If - // End If - - // End If - - else - { - TestoFirma = _TestoFirmaStart; - TestoFirmaV = _TestoFirmaStartV; - } - - Rotation(ref g); - - // Dim FotoRuotaADestra As Boolean = False - // Dim FotoRuotaASinistra As Boolean = False - - // If _UsaRotazioneAutomatica = True Then - // If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - // Dim DatiExif As New ExifReader(CType(g, Bitmap)) - - // Select Case DatiExif.Orientation - // Case ExifReader.Orientations.BottomLeft - - // Case ExifReader.Orientations.BottomRight - - // Case ExifReader.Orientations.LeftTop - - // Case ExifReader.Orientations.LftBottom - // FotoRuotaASinistra = True - // Case ExifReader.Orientations.RightBottom - - // Case ExifReader.Orientations.RightTop - - // Case ExifReader.Orientations.TopLeft - - // Case ExifReader.Orientations.TopRight - - // End Select - // End If - // End If - - // If FotoRuotaASinistra = True Then - // g.RotateFlip(RotateFlipType.Rotate270FlipNone) - // End If - // If FotoRuotaADestra = True Then - // g.RotateFlip(RotateFlipType.Rotate90FlipNone) - // End If - - var thisFormat = g.RawFormat; - if (_UsaForzaJpg == true) - { - thisFormat = ImageFormat.Jpeg; - } - - var thumbSizeSmall = new Size(); - var thumbSizeBig = new Size(); - string NomeFileSmall = ""; - string NomeFileBig2 = ""; - string NomeFileBig = ""; - if (g.Width > g.Height) - { - thumbSizeSmall = NewthumbSize(g.Width, g.Height, LarghezzaSmall, "Larghezza"); - var SizeOrig = new Size(g.Width, g.Height); - thumbSizeBig = SizeOrig; - } - else - { - thumbSizeSmall = NewthumbSize(g.Width, g.Height, AltezzaSmall, "Altezza"); - var SizeOrig = new Size(g.Width, g.Height); - thumbSizeBig = SizeOrig; - } - - NomeFileSmall = Suffisso + _NomeFileChild; - NomeFileBig = _NomeFileChild; - var imgOutputBig = new Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height); - imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution); - if (_TestoMin) - { - TestoFirmaPiccola = NomeFileBig; - } - else if (_AggNumTempMin) - { - TestoFirmaPiccola = NomeFileBig + " "; - } - - var yPosFromBottom4 = default(float); - Font crFont1 = null; - Font crFont2 = null; - var crSize1 = new SizeF(); - var crSize2 = new SizeF(); - if (_CreaMiniature == true) - { - if (_AggiungiScritteMiniature == false) - { - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4); - } - - if (_UsaOrarioMiniatura | _TestoMin | _AggTempoGaraMin | _AggNumTempMin) - { - if (TestoFirmaPiccola.Length > 0) - { - Bitmap imgOutputSmall; - imgOutputSmall = (Bitmap)imgOutputBig.Clone(); - Graphics grPhoto1; - grPhoto1 = Graphics.FromImage(imgOutputSmall); - grPhoto1.SmoothingMode = SmoothingMode.AntiAlias; - - // erano qui - - int LarghezzaStandard1; - // quick fix - DimensioneStandardMiniatura = 50; - if (_Grassetto == true) - { - crFont1 = new Font(IlFont, DimensioneStandardMiniatura, FontStyle.Bold); - crFont2 = new Font(IlFont, DimensioneStandard, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura); - crFont2 = new Font(IlFont, DimensioneStandard); - } - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1); - crSize2 = grPhoto1.MeasureString(TestoFirma, crFont1); - LarghezzaStandard1 = Conversions.ToInteger(crSize1.Width); - if (crSize1.Width > Conversions.ToSingle(g.Width)) - { - int Conta = DimensioneStandardMiniatura; - do - { - if (Conta > 20) - { - Conta -= 5; - } - else - { - Conta -= 1; - } - - if (_Grassetto == true) - { - crFont1 = new Font(_IlFont, Conta, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, Conta); - } - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1); - if (crSize1.Width < Conversions.ToSingle(g.Width)) - { - LarghezzaStandard1 = Conversions.ToInteger(crSize1.Width); - break; - } - - if (Conta <= 5) - break; - } - while (true); - DimensioneStandardMiniatura = Conta; - } - - var yPosFromBottom1 = default(float); - switch (_Posizione.ToUpper() ?? "") - { - case "ALTO": - { - yPosFromBottom1 = _Margine; - yPosFromBottom4 = _MargVert; - break; - } - - case "BASSO": - { - // yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - // yPosFromBottom1 = CType((g.Height - crFont1.Height - (g.Height * _Margine / 100) - (crFont1.Height * 0.3)), Single) - yPosFromBottom1 = Conversions.ToSingle(g.Height - crSize1.Height - g.Height * _Margine / 100d); - yPosFromBottom4 = Conversions.ToSingle(g.Height - crSize1.Height - g.Height * _MargVert / 100d); - break; - } - } - - var xCenterOfImg1 = default(float); - var StrFormat1 = new StringFormat(); - switch (_Allineamento.ToUpper() ?? "") - { - case "SINISTRA": - { - xCenterOfImg1 = Conversions.ToSingle(_Margine + LarghezzaStandard1 / 2d); - if (LarghezzaStandard1 / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - - case "CENTRO": - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - break; - } - - case "DESTRA": - { - xCenterOfImg1 = Conversions.ToSingle(g.Width - _Margine - LarghezzaStandard1 / 2d); - if (LarghezzaStandard1 / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg1 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - } - - StrFormat1.Alignment = StringAlignment.Center; - var semiTransBrush21 = new SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)); - var semiTransBrush1 = new SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)); - // quick fix - DimensioneStandardMiniatura = _DimMin; - if (_Grassetto == true) - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura, FontStyle.Bold); - } - else - { - crFont1 = new Font(_IlFont, DimensioneStandardMiniatura); - } - // asdgadfhdfhjgfsjgfjygfdhsdafa - if (_TestoMin) - { - grPhoto1.DrawString(NomeFileBig, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1f, yPosFromBottom1 + 1f), StrFormat1); - grPhoto1.DrawString(NomeFileBig, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1); - } - else if (_AggTempoGaraMin & _UsaTempoGaraTestoApplicare) - { - var Orario = new TimeSpan(DateAndTime.DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000L); - string tempstr = ""; - tempstr += ControlChars.CrLf + _TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00"); - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1f, yPosFromBottom1 + 1f), StrFormat1); - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1); - } - else if (_AggNumTempMin) - { - var Orario = new TimeSpan(DateAndTime.DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000L); - string tempstr = ""; - tempstr += NomeFileBig; - tempstr += ControlChars.CrLf + _TestoOrario + Orario.Hours.ToString("00") + ":" + Orario.Minutes.ToString("00") + ":" + Orario.Seconds.ToString("00"); - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1f, yPosFromBottom1 + 1f), StrFormat1); - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1); - } - else - { - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush21, new PointF(xCenterOfImg1 + 1f, yPosFromBottom1 + 1f), StrFormat1); - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush1, new PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1); - } - - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall), thisFormat); - var g2 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall)); - var imgOutputSmall2 = new Bitmap(g2, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall2.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall2.Dispose(); - imgOutputSmall.Dispose(); - g2.Dispose(); - FileSystem.Kill(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileSmall)); - } - else - { - var imgOutputSmall = new Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall.Dispose(); - } - } - else - { - var imgOutputSmall = new Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height); - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat); - imgOutputSmall.Dispose(); - } - } - } - - Graphics grPhoto; - grPhoto = Graphics.FromImage(imgOutputBig); - grPhoto.SmoothingMode = SmoothingMode.AntiAlias; - Font crFont = null; - var crSize = new SizeF(); - int LarghezzaStandard; - if (_Grassetto == true) - { - crFont = new Font(_IlFont, DimensioneStandard, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, DimensioneStandard); - } - - crSize = grPhoto.MeasureString(TestoFirma, crFont); - LarghezzaStandard = Conversions.ToInteger(crSize.Width); - if (crSize.Width > Conversions.ToSingle(g.Width)) - { - int Conta = DimensioneStandard; - do - { - if (Conta > 20) - { - Conta -= 5; - } - else - { - Conta -= 1; - } - - if (_Grassetto == true) - { - crFont = new Font(_IlFont, Conta, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, Conta); - } - - crSize = grPhoto.MeasureString(TestoFirma, crFont); - if (crSize.Width < Conversions.ToSingle(g.Width)) - { - LarghezzaStandard = Conversions.ToInteger(crSize.Width); - break; - } - - if (Conta <= 5) - break; - } - while (true); - DimensioneStandard = Conta; - } - - var yPosFromBottom = default(float); - var yPosFromBottom3 = default(float); - switch (_Posizione.ToUpper() ?? "") - { - case "ALTO": - { - yPosFromBottom = _Margine; - yPosFromBottom3 = _MargVert; - break; - } - - case "BASSO": - { - // yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - // yPosFromBottom = CType((g.Height - DimensioneStandard - (g.Height * _Margine / 100) - (DimensioneStandard * 0.3)), Single) - yPosFromBottom = Conversions.ToSingle(g.Height - crSize.Height - g.Height * _Margine / 100d); - yPosFromBottom3 = Conversions.ToSingle(g.Height - crSize.Height - g.Height * _MargVert / 100d); - break; - } - } - - var xCenterOfImg = default(float); - float xCenterOfImg3; - var StrFormat = new StringFormat(); - switch (_Allineamento.ToUpper() ?? "") - { - case "SINISTRA": - { - xCenterOfImg = Conversions.ToSingle(_Margine + LarghezzaStandard / 2d); - xCenterOfImg3 = Conversions.ToSingle(_MargVert + LarghezzaStandard / 2d); - if (LarghezzaStandard / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - } - - if (LarghezzaStandard / 2d > g.Width / 2d - _MargVert) - { - xCenterOfImg3 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - - case "CENTRO": - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - break; - } - - case "DESTRA": - { - xCenterOfImg = Conversions.ToSingle(g.Width - _Margine - LarghezzaStandard / 2d); - xCenterOfImg3 = Conversions.ToSingle(g.Width - _MargVert - LarghezzaStandard / 2d); - if (LarghezzaStandard / 2d > g.Width / 2d - _Margine) - { - xCenterOfImg = Conversions.ToSingle(g.Width / 2d); - } - - if (LarghezzaStandard / 2d > g.Width / 2d - _MargVert) - { - xCenterOfImg3 = Conversions.ToSingle(g.Width / 2d); - } - - break; - } - } - - StrFormat.Alignment = StringAlignment.Center; - var semiTransBrush2 = new SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)); - var semiTransBrush = new SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)); - if (FotoRuotaADestra | FotoRuotaASinistra) - { - if (_Grassetto == true) - { - crFont = new Font(_IlFont, DimVert, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, DimVert); - } - } - else if (_Grassetto == true) - { - crFont = new Font(_IlFont, DimensioneStandard, FontStyle.Bold); - } - else - { - crFont = new Font(_IlFont, DimensioneStandard); - } - - aggiungiTesto(g, DataFoto, grPhoto, NomeFileBig, crFont, semiTransBrush, semiTransBrush2, xCenterOfImg, yPosFromBottom, StrFormat, TestoFirmaV, yPosFromBottom3, yPosFromBottom4, TestoFirma, NomeFileBig2); - aggiungiLogo(imgOutputBig); - salvaFoto(imgOutputBig, thumbSizeBig, NomeFileBig, NomeFileSmall, thumbSizeSmall); - g.Dispose(); - grPhoto.Dispose(); - GC.Collect(); - } - - private void aggiungiTesto(Image g, DateTime DataFoto, Graphics grPhoto, string NomeFileBig, Font crFont, SolidBrush semiTransBrush, SolidBrush semiTransBrush2, float xCenterOfImg, float yPosFromBottom, StringFormat StrFormat, string TestoFirmav, float yPosFromBottom3, float yPosFromBottom4, string TestoFirma, string NomeFileBig2) - { - // qui scrive il testo (nomefilebig) - if (_TestoNome) - { - if (NomeData & g.PropertyIdList.Length > 0) - { - var DatiExif = new ExifReader((Bitmap)g); - DataFoto = DatiExif.DateTimeOriginal; - grPhoto.DrawString(NomeFileBig + " " + DataFoto.ToShortDateString(), crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom + 1f), StrFormat); - grPhoto.DrawString(NomeFileBig + " " + DataFoto.ToShortDateString(), crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), StrFormat); - } - else - { - grPhoto.DrawString(NomeFileBig, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom + 1f), StrFormat); - grPhoto.DrawString(NomeFileBig, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), StrFormat); - } - } - - if (_TestoNome == false) - { - if (FotoRuotaADestra | FotoRuotaASinistra) - { - if (_TestoMin == false) - { - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom3 + 1f), StrFormat); - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom3), StrFormat); - } - - if (_TestoMin == true) - { - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom4 + 1f), StrFormat); - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom4), StrFormat); - } - } - else - { - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush2, new PointF(xCenterOfImg + 1f, yPosFromBottom + 1f), StrFormat); - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush, new PointF(xCenterOfImg, yPosFromBottom), StrFormat); - } - } - - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileBig2 = NomeFileBig; - NomeFileBig = NomeFileBig.Substring(0, NomeFileBig.Length - 4) + Codice + NomeFileBig.Substring(NomeFileBig.Length - 4); - } - } - - private void aggiungiLogo(Bitmap imgOutputBig) - { - // imgOutputBig - if (_LogoAggiungi == true & File.Exists(_LogoNomeFile)) - { - var ImmagineLogo = Image.FromFile(_LogoNomeFile); - var LogoColoreTrasparente = Color.White; - // Dim bmWatermark As Bitmap - - // * Create a Bitmap based on the previously modified photograph Bitmap - // bmWatermark = New Bitmap(imgOutputBig) - // bmWatermark.SetResolution(imgOutputBig.HorizontalResolution, imgOutputBig.VerticalResolution) - - // * Load this Bitmap into a new Graphic Object - var grWatermark = Graphics.FromImage(imgOutputBig); - - // * To achieve a transulcent watermark we will apply (2) color manipulations - var imageAttributes = new ImageAttributes(); - - // * The first step replace the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0) - var colorMap = new ColorMap(); - - // * background this will be the color we search for and replace with transparency - colorMap.OldColor = LogoColoreTrasparente; - colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); - var remapTable = new[] { colorMap }; - 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 - 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, Conversions.ToSingle(_LogoTrasparenza) / 100f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; - var wmColorMatrix = new ColorMatrix(colorMatrixElements); - imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); - int FotoLogoH = _LogoAltezza; - int FotoLogoW = _LogoLarghezza; - double FattoreAlt = ImmagineLogo.Height / (double)FotoLogoH; - double FattoreLarg = ImmagineLogo.Width / (double)FotoLogoW; - Size NuovaSize; - if (FattoreLarg > FattoreAlt) - { - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoW, "Larghezza"); - } - else - { - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoH, "Altezza"); - } - - int MargineUsato; - int MargineL; - bool InPercentualeL; - if (_LogoMargine.EndsWith("%") == true) - { - InPercentualeL = true; - } - else - { - InPercentualeL = false; - } - - MargineL = Conversions.ToInteger(Conversion.Val(_LogoMargine)); - if (InPercentualeL == true) - { - MargineUsato = Conversions.ToInteger(imgOutputBig.Height * MargineL / 100d); - } - else - { - MargineUsato = MargineL; - } - - var xPosOfWm = default(int); - var yPosOfWm = default(int); - switch (_LogoPosizioneH.ToUpper() ?? "") - { - case "SINISTRA": - case "NESSUNA": - { - xPosOfWm = MargineUsato; - break; - } - - case "CENTRO": - { - xPosOfWm = Conversions.ToInteger((imgOutputBig.Width - NuovaSize.Width) / 2d); - break; - } - - case "DESTRA": - { - xPosOfWm = imgOutputBig.Width - NuovaSize.Width - MargineUsato; - break; - } - } - - switch (_LogoPosizioneV.ToUpper() ?? "") - { - case "ALTO": - case "NESSUNA": - { - yPosOfWm = MargineUsato; - break; - } - - case "CENTRO": - { - yPosOfWm = Conversions.ToInteger((imgOutputBig.Height - NuovaSize.Height) / 2d); - break; - } - - case "BASSO": - { - yPosOfWm = imgOutputBig.Height - NuovaSize.Height - MargineUsato; - break; - } - } - - grWatermark.DrawImage(ImmagineLogo, new Rectangle(xPosOfWm, yPosOfWm, NuovaSize.Width, NuovaSize.Height), 0, 0, ImmagineLogo.Width, ImmagineLogo.Height, GraphicsUnit.Pixel, imageAttributes); - grWatermark.Dispose(); - } - } - - private void salvaFoto(Bitmap imgOutputBig, Size thumbSizeBig, string NomeFileBig, string NomeFileSmall, Size thumbSizeSmall) - { - if (_FotoGrandeDimOrigina == false) - { - // attenzione non controlla se è png - // imgOutputBig.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig, Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig), jpegQuality); - var g2 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - if (g2.Width > g2.Height) - { - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _LarghezzaBig, "Larghezza"); - } - else - { - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _AltezzaBig, "Altezza"); - } - - var imgOutputBig2 = new Bitmap(g2, thumbSizeBig.Width, thumbSizeBig.Height); - // imgOutputBig2.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig2, Path.Combine(_DestDir.FullName, NomeFileBig), jpegQuality); - // imgOutputBig2.Dispose() - // imgOutputBig.Dispose() - g2.Dispose(); - } - else - { - // imgOutputBig.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig, Path.Combine(_DestDir.FullName, NomeFileBig), jpegQuality); - imgOutputBig.Dispose(); - } - - if (_CreaMiniature) - { - if (_AggiungiScritteMiniature == true) - { - Image g1; - if (_FotoGrandeDimOrigina == false) - { - g1 = Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - } - else - { - g1 = Image.FromFile(Path.Combine(_DestDir.FullName, NomeFileBig)); - } - - var imgOutputSmall = new Bitmap(g1, thumbSizeSmall.Width, thumbSizeSmall.Height); - if ((_DirectorySorgente.ToUpper() ?? "") == (_DirectoryDestinazione.ToUpper() ?? "")) - { - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) + Codice + NomeFileSmall.Substring(NomeFileSmall.Length - 4); - } - // imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - salvaImmagineCustomQuality(imgOutputSmall, Path.Combine(_DestDir.FullName, NomeFileSmall), jpegQualityMin); - // imgOutputSmall.Dispose() - g1.Dispose(); - } - } - - if (File.Exists(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)) == true) - { - FileSystem.Kill(Path.Combine(_DestDir.FullName, "Temp_" + NomeFileBig)); - } - } - - private void salvaImmagineCustomQuality(Bitmap imageToSave, string nomeFileFinale, long quality) - { - var JgpEncoder = GetEncoder(ImageFormat.Jpeg); - var MyEncoder = Encoder.Quality; - var MyEncoderParameters = new EncoderParameters(1); - var MyEncoderParameter = new EncoderParameter(MyEncoder, jpegQuality); - MyEncoderParameters.Param[0] = MyEncoderParameter; - imageToSave.Save(nomeFileFinale, JgpEncoder, MyEncoderParameters); - imageToSave.Dispose(); - } - - private ImageCodecInfo GetEncoder(ImageFormat format) - { - var codecs = ImageCodecInfo.GetImageDecoders(); - foreach (var codec in codecs) - { - if (codec.FormatID == format.Guid) - { - return codec; - } - } - - return null; - } - - - - - - - /// - /// Calculate the Size of the New image - /// - /// Larghezza - /// Altezza - /// - /// - /// - /// - public Size NewthumbSize(int currentwidth, int currentheight, int MaxPixel, string TipoSize) - { - // e - // *** Larghezza, Altezza, Auto - - double tempMultiplier; - if ((TipoSize.ToUpper() ?? "") == ("Larghezza".ToUpper() ?? "")) - { - tempMultiplier = MaxPixel / (double)currentwidth; - } - else if ((TipoSize.ToUpper() ?? "") == ("Altezza".ToUpper() ?? "")) - { - tempMultiplier = MaxPixel / (double)currentheight; - } - else if (currentheight > currentwidth) // portrait - { - tempMultiplier = MaxPixel / (double)currentheight; - } - else - { - tempMultiplier = MaxPixel / (double)currentwidth; - } - - var NewSize = new Size((int)Math.Round(currentwidth * tempMultiplier), (int)Math.Round(currentheight * tempMultiplier)); - return NewSize; - } - - public string DirectorySorgente - { - get - { - return _DirectorySorgente; - } - - set - { - _DirectorySorgente = value; - } - } - - public string DirectoryDestinazione - { - get - { - return _DirectoryDestinazione; - } - - set - { - _DirectoryDestinazione = value; - } - } - - public DirectoryInfo SourceDir - { - get - { - return _SourceDir; - } - - set - { - _SourceDir = value; - } - } - - public DirectoryInfo DestDirStart - { - get - { - return _DestDirStart; - } - - set - { - _DestDirStart = value; - } - } - - public string TestoFirmaStart - { - get - { - return _TestoFirmaStart; - } - - set - { - _TestoFirmaStart = value; - } - } - - public string TestoFirmaStartV - { - get - { - return _TestoFirmaStartV; - } - - set - { - _TestoFirmaStartV = value; - } - } - - public DateTime DataPartenza - { - get - { - return _DataPartenza; - } - - set - { - _DataPartenza = value; - } - } - - public string TestoOrario - { - get - { - return _TestoOrario; - } - - set - { - _TestoOrario = value; - } - } - - public int DimStandard - { - get - { - return _DimStandard; - } - - set - { - _DimStandard = value; - } - } - - public int DimStandardMiniatura - { - get - { - return _DimStandardMiniatura; - } - - set - { - _DimStandardMiniatura = value; - } - } - - public bool NomeData - { - get - { - return _NomeData; - } - - set - { - _NomeData = value; - } - } - - public bool TestoNome - { - get - { - return _TestoNome; - } - - set - { - _TestoNome = value; - } - } - - public bool UsaOrarioMiniatura - { - get - { - return _UsaOrarioMiniatura; - } - - set - { - _UsaOrarioMiniatura = value; - } - } - - public bool UsaOrarioTestoApplicare - { - get - { - return _UsaOrarioTestoApplicare; - } - - set - { - _UsaOrarioTestoApplicare = value; - } - } - - public bool UsaTempoGaraTestoApplicare - { - get - { - return _UsaTempoGaraTestoApplicare; - } - - set - { - _UsaTempoGaraTestoApplicare = value; - } - } - - public bool UsaRotazioneAutomatica - { - get - { - return _UsaRotazioneAutomatica; - } - - set - { - _UsaRotazioneAutomatica = value; - } - } - - public bool UsaForzaJpg - { - get - { - return _UsaForzaJpg; - } - - set - { - _UsaForzaJpg = value; - } - } - - public int LarghezzaSmall - { - get - { - return _LarghezzaSmall; - } - - set - { - _LarghezzaSmall = value; - } - } - - public int AltezzaSmall - { - get - { - return _AltezzaSmall; - } - - set - { - _AltezzaSmall = value; - } - } - - public bool CreaMiniature - { - get - { - return _CreaMiniature; - } - - set - { - _CreaMiniature = value; - } - } - - public bool AggiungiScritteMiniature - { - get - { - return _AggiungiScritteMiniature; - } - - set - { - _AggiungiScritteMiniature = value; - } - } - - public string NomeFileChild - { - get - { - return _NomeFileChild; - } - - set - { - _NomeFileChild = value; - } - } - - public string Suffisso - { - get - { - return _Suffisso; - } - - set - { - _Suffisso = value; - } - } - - public string Codice - { - get - { - return _Codice; - } - - set - { - _Codice = value; - } - } - - public int Trasparenza - { - get - { - return _Trasparenza; - } - - set - { - _Trasparenza = value; - } - } - - public string IlFont - { - get - { - return _IlFont; - } - - set - { - _IlFont = value; - } - } - - public bool Grassetto - { - get - { - return _Grassetto; - } - - set - { - _Grassetto = value; - } - } - - public string Posizione - { - get - { - return _Posizione; - } - - set - { - _Posizione = value; - } - } - - public string Allineamento - { - get - { - return _Allineamento; - } - - set - { - _Allineamento = value; - } - } - - public int Margine - { - get - { - return _Margine; - } - - set - { - _Margine = value; - } - } - - public int LogoAltezza - { - get - { - return _LogoAltezza; - } - - set - { - _LogoAltezza = value; - } - } - - public int LogoLarghezza - { - get - { - return _LogoLarghezza; - } - - set - { - _LogoLarghezza = value; - } - } - - public int FontColoreR - { - get - { - return _FontColoreR; - } - - set - { - _FontColoreR = value; - } - } - - public int FontColoreG - { - get - { - return _FontColoreG; - } - - set - { - _FontColoreG = value; - } - } - - public int FontColoreB - { - get - { - return _FontColoreB; - } - - set - { - _FontColoreB = value; - } - } - - public Color fontColoreRGB - { - get - { - return _fontColoreRGB; - } - - set - { - _fontColoreRGB = value; - } - } - - public bool LogoAggiungi - { - get - { - return _LogoAggiungi; - } - - set - { - _LogoAggiungi = value; - } - } - - public string LogoNomeFile - { - get - { - return _LogoNomeFile; - } - - set - { - _LogoNomeFile = value; - } - } - - public string LogoTrasparenza - { - get - { - return _LogoTrasparenza; - } - - set - { - _LogoTrasparenza = value; - } - } - - public string LogoMargine - { - get - { - return _LogoMargine; - } - - set - { - _LogoMargine = value; - } - } - - public string LogoPosizioneH - { - get - { - return _LogoPosizioneH; - } - - set - { - _LogoPosizioneH = value; - } - } - - public string LogoPosizioneV - { - get - { - return _LogoPosizioneV; - } - - set - { - _LogoPosizioneV = value; - } - } - - public bool FotoGrandeDimOrigina - { - get - { - return _FotoGrandeDimOrigina; - } - - set - { - _FotoGrandeDimOrigina = value; - } - } - - public int AltezzaBig - { - get - { - return _AltezzaBig; - } - - set - { - _AltezzaBig = value; - } - } - - public int LarghezzaBig - { - get - { - return _LarghezzaBig; - } - - set - { - _LarghezzaBig = value; - } - } - - public DirectoryInfo DestDir - { - get - { - return _DestDir; - } - - set - { - _DestDir = value; - } - } - - public int DimVert - { - get - { - return _DimVert; - } - - set - { - _DimVert = value; - } - } - - public int MargVert - { - get - { - return _MargVert; - } - - set - { - _MargVert = value; - } - } - - public bool TestoMin - { - get - { - return _TestoMin; - } - - set - { - _TestoMin = value; - } - } - - public int DimMin - { - get - { - return _DimMin; - } - - set - { - _DimMin = value; - } - } - - public bool SecretDefault - { - get - { - return _SecretDefault; - } - - set - { - _SecretDefault = value; - } - } - - public bool SecretBig - { - get - { - return _SecretBig; - } - - set - { - _SecretBig = value; - } - } - - public bool SecretSmall - { - get - { - return _SecretSmall; - } - - set - { - _SecretSmall = value; - } - } - - public string SecretPathSmall - { - get - { - return _SecretPathSmall; - } - - set - { - _SecretPathSmall = value; - } - } - - public string SecretPathBig - { - get - { - return _SecretPathBig; - } - - set - { - _SecretPathBig = value; - } - } - - public bool AggTempoGaraMin - { - get - { - return _AggTempoGaraMin; - } - - set - { - _AggTempoGaraMin = value; - } - } - - public bool AggNumTempMin - { - get - { - return _AggNumTempMin; - } - - set - { - _AggNumTempMin = value; - } - } - - public long jpegQuality - { - get - { - return _jpegQuality; - } - - set - { - _jpegQuality = value; - } - } - - public long jpegQualityMin - { - get - { - return _jpegQualityMin; - } - - set - { - _jpegQualityMin = value; - } - } - } -} \ No newline at end of file diff --git a/imagecatalog/CreaImmagineSeparateThread.vb b/imagecatalog/CreaImmagineSeparateThread.vb deleted file mode 100644 index 59767e6..0000000 --- a/imagecatalog/CreaImmagineSeparateThread.vb +++ /dev/null @@ -1,1409 +0,0 @@ -Imports System.IO -Imports System.Drawing.Drawing2D -Imports System.Drawing.Imaging -'Imports System.Threading - -Public Class CreaImmagineSeparateThread -#Region "dichiarazioni" - Private _DirectorySorgente As String - Private _DirectoryDestinazione As String - - Private _DimVert As Integer - Private _MargVert As Integer - - Private _SourceDir As DirectoryInfo - Private _DestDirStart As DirectoryInfo - Private _DimStandard As Integer - Private _DimStandardMiniatura As Integer - - Private _NomeData As Boolean - Private _TestoNome As Boolean - Private _UsaOrarioMiniatura As Boolean - Private _UsaOrarioTestoApplicare As Boolean - Private _UsaTempoGaraTestoApplicare As Boolean - Private _TestoFirmaStart As String - Private _TestoFirmaStartV As String - Private _DataPartenza As DateTime - Private _TestoOrario As String - - Private _UsaRotazioneAutomatica As Boolean - Private _UsaForzaJpg As Boolean - - Private _LarghezzaSmall As Integer - Private _AltezzaSmall As Integer - - Private _CreaMiniature As Boolean - Private _AggiungiScritteMiniature As Boolean - Private _AggTempoGaraMin As Boolean - Private _AggNumTempMin As Boolean - - - Private _NomeFileChild As String - Private _Suffisso As String - Private _Codice As String - - Private _Trasparenza As Integer - Private _IlFont As String - Private _Grassetto As Boolean - - Private _Posizione As String - Private _Allineamento As String - Private _Margine As Integer - - Private _LogoAltezza As Integer - Private _LogoLarghezza As Integer - - Private _FontColoreR As Integer - Private _FontColoreG As Integer - Private _FontColoreB As Integer - Private _fontColoreRGB As Color - - Private _LogoAggiungi As Boolean - Private _LogoNomeFile As String - Private _LogoTrasparenza As String - Private _LogoMargine As String - Private _LogoPosizioneH As String - Private _LogoPosizioneV As String - - Private _FotoGrandeDimOrigina As Boolean - Private _AltezzaBig As Integer - Private _LarghezzaBig As Integer - Private _DestDir As DirectoryInfo - Private _DimMin As Integer - - Private _TestoMin As Boolean - - Private _SecretDefault As Boolean - Private _SecretBig As Boolean - Private _SecretSmall As Boolean - - Private _SecretPathSmall As String - Private _SecretPathBig As String - - Private _jpegQuality As Long - Private _jpegQualityMin As Long - - Private FotoRuotaADestra As Boolean = False - Private FotoRuotaASinistra As Boolean = False - - Private TempMinText As String = "" - 'Private crFont1 As Font - - -#End Region - - Private Sub ProcA(ByRef g As System.Drawing.Image, ByRef DataFoto As DateTime, ByRef TestoFirma As String, ByRef TestoFirmaV As String, ByRef TestoFirmaPiccola As String, ByRef DataPartenzaI As DateTime) - If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - Dim DatiExif As New ExifReader(CType(g, Bitmap)) - DataFoto = DatiExif.DateTimeOriginal - TestoFirma = _TestoFirmaStart - TestoFirmaV = _TestoFirmaStartV - - If DataFoto.Year <> 1 Then - TestoFirmaPiccola = DataFoto.ToShortTimeString - If _UsaOrarioTestoApplicare = True Then - TestoFirma &= " " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - TestoFirmaV &= " " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - End If - If _UsaTempoGaraTestoApplicare = True Then - Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - TestoFirma &= " " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - TestoFirmaV &= " " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - End If - End If - - End If - End Sub - - Private Sub Rotation(ByRef g As System.Drawing.Image) - - FotoRuotaADestra = False - FotoRuotaASinistra = False - - If _UsaRotazioneAutomatica = True Then - If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - Dim DatiExif As New ExifReader(CType(g, Bitmap)) - - Select Case DatiExif.Orientation - Case ExifReader.Orientations.BottomLeft - - Case ExifReader.Orientations.BottomRight - - Case ExifReader.Orientations.LeftTop - - Case ExifReader.Orientations.LftBottom - FotoRuotaASinistra = True - Case ExifReader.Orientations.RightBottom - - Case ExifReader.Orientations.RightTop - - Case ExifReader.Orientations.TopLeft - - Case ExifReader.Orientations.TopRight - - End Select - End If - End If - - If FotoRuotaASinistra = True Then - g.RotateFlip(RotateFlipType.Rotate270FlipNone) - End If - If FotoRuotaADestra = True Then - g.RotateFlip(RotateFlipType.Rotate90FlipNone) - End If - - - - End Sub - - - Public Sub CreaImmagineThread(ByVal Info As String) - Dim TestoFirma As String = "" - Dim TestoFirmaV As String = "" - - Dim AlphaScelta As Integer = CType((255 * (100 - _Trasparenza) / 100), Integer) - - Dim DimensioneStandard As Integer - Dim DimensioneStandardMiniatura As Integer - - Dim DataFoto As DateTime - Dim DataPartenzaI As DateTime = _DataPartenza - If _TestoOrario.Length > 0 Then - _TestoOrario &= " " - End If - Dim TestoFirmaPiccola As String = "" - - Dim FileConta As Integer = 0 - Dim ContaFileXDir As Integer = 0 - Dim ContaDirXDir As Integer = 0 - Dim TestoTemp As String = "" - Dim ContaTemp As Integer = 0 - - DimensioneStandard = _DimStandard - DimensioneStandardMiniatura = _DimStandardMiniatura - - Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_SourceDir.FullName, _NomeFileChild)) - 'dati extra in fondo - If _UsaOrarioTestoApplicare Or - _UsaTempoGaraTestoApplicare Or - _UsaOrarioMiniatura Or - _TestoMin Or - _AggTempoGaraMin Or - _AggNumTempMin Then - - ProcA(g, DataFoto, TestoFirma, TestoFirmaV, TestoFirmaPiccola, DataPartenzaI) - - 'If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - ' Dim DatiExif As New ExifReader(CType(g, Bitmap)) - ' DataFoto = DatiExif.DateTimeOriginal - ' TestoFirma = _TestoFirmaStart - ' TestoFirmaV = _TestoFirmaStartV - - ' If DataFoto.Year <> 1 Then - ' TestoFirmaPiccola = DataFoto.ToShortTimeString - ' If _UsaOrarioTestoApplicare = True Then - ' TestoFirma &= " - " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - ' TestoFirmaV &= " - " & DataFoto.ToShortDateString & " " & DataFoto.ToLongTimeString - ' End If - ' If _UsaTempoGaraTestoApplicare = True Then - ' Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - ' TestoFirma &= " - " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - ' TestoFirmaV &= " - " & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - ' End If - ' End If - - 'End If - - Else - TestoFirma = _TestoFirmaStart - TestoFirmaV = _TestoFirmaStartV - - End If - - - Rotation(g) - - 'Dim FotoRuotaADestra As Boolean = False - 'Dim FotoRuotaASinistra As Boolean = False - - 'If _UsaRotazioneAutomatica = True Then - ' If g.PropertyIdList.Length > 0 Then ' ci sono dati exif - ' Dim DatiExif As New ExifReader(CType(g, Bitmap)) - - ' Select Case DatiExif.Orientation - ' Case ExifReader.Orientations.BottomLeft - - ' Case ExifReader.Orientations.BottomRight - - ' Case ExifReader.Orientations.LeftTop - - ' Case ExifReader.Orientations.LftBottom - ' FotoRuotaASinistra = True - ' Case ExifReader.Orientations.RightBottom - - ' Case ExifReader.Orientations.RightTop - - ' Case ExifReader.Orientations.TopLeft - - ' Case ExifReader.Orientations.TopRight - - ' End Select - ' End If - 'End If - - 'If FotoRuotaASinistra = True Then - ' g.RotateFlip(RotateFlipType.Rotate270FlipNone) - 'End If - 'If FotoRuotaADestra = True Then - ' g.RotateFlip(RotateFlipType.Rotate90FlipNone) - 'End If - - Dim thisFormat As System.Drawing.Imaging.ImageFormat = g.RawFormat - If _UsaForzaJpg = True Then - thisFormat = System.Drawing.Imaging.ImageFormat.Jpeg - End If - - Dim thumbSizeSmall As New Size - Dim thumbSizeBig As New Size - Dim NomeFileSmall As String = "" - - Dim NomeFileBig2 As String = "" - Dim NomeFileBig As String = "" - - - If g.Width > g.Height Then - thumbSizeSmall = NewthumbSize(g.Width, g.Height, LarghezzaSmall, "Larghezza") - Dim SizeOrig As New Size(g.Width, g.Height) - thumbSizeBig = SizeOrig - Else - thumbSizeSmall = NewthumbSize(g.Width, g.Height, AltezzaSmall, "Altezza") - Dim SizeOrig As New Size(g.Width, g.Height) - thumbSizeBig = SizeOrig - End If - - NomeFileSmall = Suffisso & _NomeFileChild - NomeFileBig = _NomeFileChild - - Dim imgOutputBig As New Bitmap(g, thumbSizeBig.Width, thumbSizeBig.Height) - imgOutputBig.SetResolution(g.HorizontalResolution, g.VerticalResolution) - - If _TestoMin Then - TestoFirmaPiccola = NomeFileBig - ElseIf _AggNumTempMin Then - TestoFirmaPiccola = NomeFileBig + " " - End If - Dim yPosFromBottom4 As Single - - Dim crFont1 As Font = Nothing - Dim crFont2 As Font = Nothing - Dim crSize1 As SizeF = New SizeF - Dim crSize2 As SizeF = New SizeF - - If _CreaMiniature = True Then - If _AggiungiScritteMiniature = False Then - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) & Codice & NomeFileSmall.Substring(NomeFileSmall.Length - 4) - End If - If _UsaOrarioMiniatura Or - _TestoMin Or - _AggTempoGaraMin Or - _AggNumTempMin Then - - If TestoFirmaPiccola.Length > 0 Then - Dim imgOutputSmall As Bitmap - imgOutputSmall = CType(imgOutputBig.Clone, Bitmap) - - Dim grPhoto1 As Graphics - grPhoto1 = Graphics.FromImage(imgOutputSmall) - grPhoto1.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias - - 'erano qui - - Dim LarghezzaStandard1 As Integer - 'quick fix - DimensioneStandardMiniatura = 50 - If _Grassetto = True Then - crFont1 = New Font(IlFont, DimensioneStandardMiniatura, FontStyle.Bold) - crFont2 = New Font(IlFont, DimensioneStandard, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura) - crFont2 = New Font(IlFont, DimensioneStandard) - End If - - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1) - crSize2 = grPhoto1.MeasureString(TestoFirma, crFont1) - LarghezzaStandard1 = CType(crSize1.Width, Integer) - - If crSize1.Width > CType(g.Width, Single) Then - Dim Conta As Integer = DimensioneStandardMiniatura - Do - If Conta > 20 Then - Conta -= 5 - Else - Conta -= 1 - End If - If _Grassetto = True Then - crFont1 = New Font(_IlFont, Conta, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, Conta) - End If - crSize1 = grPhoto1.MeasureString(TestoFirmaPiccola, crFont1) - If crSize1.Width < CType(g.Width, Single) Then - LarghezzaStandard1 = CType(crSize1.Width, Integer) - Exit Do - End If - If Conta <= 5 Then Exit Do - Loop - DimensioneStandardMiniatura = Conta - End If - - Dim yPosFromBottom1 As Single - - - - Select Case _Posizione.ToUpper - Case "ALTO" - - yPosFromBottom1 = (_Margine) - yPosFromBottom4 = (_MargVert) - - Case "BASSO" - 'yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - 'yPosFromBottom1 = CType((g.Height - crFont1.Height - (g.Height * _Margine / 100) - (crFont1.Height * 0.3)), Single) - yPosFromBottom1 = CType((g.Height - crSize1.Height - (g.Height * _Margine / 100)), Single) - yPosFromBottom4 = CType((g.Height - crSize1.Height - (g.Height * _MargVert / 100)), Single) - - End Select - - Dim xCenterOfImg1 As Single - - Dim StrFormat1 As StringFormat = New StringFormat - Select Case _Allineamento.ToUpper - Case "SINISTRA" - xCenterOfImg1 = CType((_Margine + (LarghezzaStandard1 / 2)), Single) - - If (LarghezzaStandard1 / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg1 = CType((g.Width / 2), Single) - End If - - - Case "CENTRO" - xCenterOfImg1 = CType((g.Width / 2), Single) - - - Case "DESTRA" - xCenterOfImg1 = CType((g.Width - _Margine - (LarghezzaStandard1 / 2)), Single) - - If (LarghezzaStandard1 / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg1 = CType((g.Width / 2), Single) - End If - - - End Select - StrFormat1.Alignment = StringAlignment.Center - - Dim semiTransBrush21 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)) - Dim semiTransBrush1 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)) - 'quick fix - DimensioneStandardMiniatura = _DimMin - - If _Grassetto = True Then - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura, FontStyle.Bold) - Else - crFont1 = New Font(_IlFont, DimensioneStandardMiniatura) - End If - 'asdgadfhdfhjgfsjgfjygfdhsdafa - If _TestoMin Then - grPhoto1.DrawString(NomeFileBig, crFont1, semiTransBrush21, New PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1) - grPhoto1.DrawString(NomeFileBig, crFont1, semiTransBrush1, New PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1) - ElseIf _AggTempoGaraMin And _UsaTempoGaraTestoApplicare Then - Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - Dim tempstr As String = "" - - - tempstr &= ControlChars.CrLf & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - - - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, New PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1) - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, New PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1) - - ElseIf _AggNumTempMin Then - Dim Orario As TimeSpan = New TimeSpan(DateDiff(DateInterval.Second, DataPartenzaI, DataFoto) * 10000000) - Dim tempstr As String = "" - tempstr &= NomeFileBig - - tempstr &= ControlChars.CrLf & _TestoOrario & Orario.Hours.ToString("00") & ":" & Orario.Minutes.ToString("00") & ":" & Orario.Seconds.ToString("00") - - - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush21, New PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1) - grPhoto1.DrawString(tempstr, crFont1, semiTransBrush1, New PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1) - - - Else - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush21, New PointF(xCenterOfImg1 + 1, yPosFromBottom1 + 1), StrFormat1) - grPhoto1.DrawString(TestoFirmaPiccola, crFont1, semiTransBrush1, New PointF(xCenterOfImg1, yPosFromBottom1), StrFormat1) - End If - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall), thisFormat) - Dim g2 As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall)) - Dim imgOutputSmall2 As New Bitmap(g2, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall2.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - - imgOutputSmall2.Dispose() - imgOutputSmall.Dispose() - g2.Dispose() - Kill(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileSmall)) - Else - Dim imgOutputSmall As New Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - imgOutputSmall.Dispose() - End If - Else - Dim imgOutputSmall As New Bitmap(g, thumbSizeSmall.Width, thumbSizeSmall.Height) - imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - imgOutputSmall.Dispose() - End If - End If - End If - - Dim grPhoto As Graphics - grPhoto = Graphics.FromImage(imgOutputBig) - grPhoto.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias - - Dim crFont As Font = Nothing - Dim crSize As SizeF = New SizeF - Dim LarghezzaStandard As Integer - - If _Grassetto = True Then - crFont = New Font(_IlFont, DimensioneStandard, FontStyle.Bold) - Else - crFont = New Font(_IlFont, DimensioneStandard) - End If - crSize = grPhoto.MeasureString(TestoFirma, crFont) - LarghezzaStandard = CType(crSize.Width, Integer) - - If crSize.Width > CType(g.Width, Single) Then - Dim Conta As Integer = DimensioneStandard - Do - If Conta > 20 Then - Conta -= 5 - Else - Conta -= 1 - End If - If _Grassetto = True Then - crFont = New Font(_IlFont, Conta, FontStyle.Bold) - Else - crFont = New Font(_IlFont, Conta) - End If - crSize = grPhoto.MeasureString(TestoFirma, crFont) - If crSize.Width < CType(g.Width, Single) Then - LarghezzaStandard = CType(crSize.Width, Integer) - Exit Do - End If - If Conta <= 5 Then Exit Do - Loop - DimensioneStandard = Conta - End If - - Dim yPosFromBottom As Single - Dim yPosFromBottom3 As Single - Select Case _Posizione.ToUpper - Case "ALTO" - yPosFromBottom = (_Margine) - yPosFromBottom3 = (_MargVert) - - Case "BASSO" - 'yPosFromBottom = (g.Height - _Margine - DimensioneStandard) - 'yPosFromBottom = CType((g.Height - DimensioneStandard - (g.Height * _Margine / 100) - (DimensioneStandard * 0.3)), Single) - yPosFromBottom = CType((g.Height - crSize.Height - (g.Height * _Margine / 100)), Single) - yPosFromBottom3 = CType((g.Height - crSize.Height - (g.Height * _MargVert / 100)), Single) - End Select - - Dim xCenterOfImg As Single - Dim xCenterOfImg3 As Single - Dim StrFormat As StringFormat = New StringFormat - Select Case _Allineamento.ToUpper - Case "SINISTRA" - xCenterOfImg = CType((_Margine + (LarghezzaStandard / 2)), Single) - xCenterOfImg3 = CType((_MargVert + (LarghezzaStandard / 2)), Single) - If (LarghezzaStandard / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg = CType((g.Width / 2), Single) - End If - If (LarghezzaStandard / 2) > (g.Width / 2) - _MargVert Then - xCenterOfImg3 = CType((g.Width / 2), Single) - End If - - Case "CENTRO" - xCenterOfImg = CType((g.Width / 2), Single) - - Case "DESTRA" - xCenterOfImg = CType((g.Width - _Margine - (LarghezzaStandard / 2)), Single) - xCenterOfImg3 = CType((g.Width - _MargVert - (LarghezzaStandard / 2)), Single) - If (LarghezzaStandard / 2) > (g.Width / 2) - _Margine Then - xCenterOfImg = CType((g.Width / 2), Single) - End If - If (LarghezzaStandard / 2) > (g.Width / 2) - _MargVert Then - xCenterOfImg3 = CType((g.Width / 2), Single) - End If - - End Select - StrFormat.Alignment = StringAlignment.Center - - Dim semiTransBrush2 As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, 0, 0, 0)) - Dim semiTransBrush As SolidBrush = New SolidBrush(Color.FromArgb(AlphaScelta, _FontColoreR, _FontColoreG, _FontColoreB)) - - If FotoRuotaADestra Or FotoRuotaASinistra Then - - If _Grassetto = True Then - crFont = New Font(_IlFont, DimVert, FontStyle.Bold) - Else - crFont = New Font(_IlFont, DimVert) - End If - - Else - - If _Grassetto = True Then - crFont = New Font(_IlFont, DimensioneStandard, FontStyle.Bold) - Else - crFont = New Font(_IlFont, DimensioneStandard) - End If - End If - - aggiungiTesto(g, DataFoto, grPhoto, NomeFileBig, crFont, semiTransBrush, - semiTransBrush2, xCenterOfImg, yPosFromBottom, StrFormat, - TestoFirmaV, yPosFromBottom3, yPosFromBottom4, TestoFirma, NomeFileBig2) - - aggiungiLogo(imgOutputBig) - salvaFoto(imgOutputBig, thumbSizeBig, NomeFileBig, NomeFileSmall, thumbSizeSmall) - - g.Dispose() - grPhoto.Dispose() - GC.Collect() - - End Sub - - Private Sub aggiungiTesto(g As Image, DataFoto As Date, grPhoto As Graphics, NomeFileBig As String, crFont As Font, semiTransBrush As SolidBrush, - semiTransBrush2 As SolidBrush, xCenterOfImg As Single, yPosFromBottom As Single, StrFormat As StringFormat, - TestoFirmav As String, yPosFromBottom3 As Single, yPosFromBottom4 As Single, TestoFirma As String, NomeFileBig2 As String) - 'qui scrive il testo (nomefilebig) - If _TestoNome Then - If NomeData And g.PropertyIdList.Length > 0 Then - Dim DatiExif As New ExifReader(CType(g, Bitmap)) - DataFoto = DatiExif.DateTimeOriginal - - - grPhoto.DrawString((NomeFileBig & " " & DataFoto.ToShortDateString), crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat) - grPhoto.DrawString((NomeFileBig & " " & DataFoto.ToShortDateString), crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom), StrFormat) - - - Else - - grPhoto.DrawString(NomeFileBig, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat) - grPhoto.DrawString(NomeFileBig, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom), StrFormat) - - End If - End If - - If _TestoNome = False Then - If FotoRuotaADestra Or FotoRuotaASinistra Then - If _TestoMin = False Then - - - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom3 + 1), StrFormat) - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom3), StrFormat) - End If - If _TestoMin = True Then - - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom4 + 1), StrFormat) - grPhoto.DrawString(TestoFirmav, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom4), StrFormat) - - End If - Else - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush2, New PointF(xCenterOfImg + 1, yPosFromBottom + 1), StrFormat) - grPhoto.DrawString(TestoFirma, crFont, semiTransBrush, New PointF(xCenterOfImg, yPosFromBottom), StrFormat) - - - End If - End If - - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileBig2 = NomeFileBig - NomeFileBig = NomeFileBig.Substring(0, NomeFileBig.Length - 4) & Codice & NomeFileBig.Substring(NomeFileBig.Length - 4) - End If - End Sub - - Private Sub aggiungiLogo(imgOutputBig As Bitmap) - 'imgOutputBig - If _LogoAggiungi = True And File.Exists(_LogoNomeFile) Then - - Dim ImmagineLogo As Image = Image.FromFile(_LogoNomeFile) - - Dim LogoColoreTrasparente As Color = Color.White - 'Dim bmWatermark As Bitmap - - '* Create a Bitmap based on the previously modified photograph Bitmap - 'bmWatermark = New Bitmap(imgOutputBig) - 'bmWatermark.SetResolution(imgOutputBig.HorizontalResolution, imgOutputBig.VerticalResolution) - - '* Load this Bitmap into a new Graphic Object - Dim grWatermark As Graphics = Graphics.FromImage(imgOutputBig) - - '* To achieve a transulcent watermark we will apply (2) color manipulations - Dim imageAttributes As Imaging.ImageAttributes = New Imaging.ImageAttributes - - '* The first step replace the background color with one that is trasparent (Alpha=0, R=0, G=0, B=0) - Dim colorMap As Imaging.ColorMap = New Imaging.ColorMap - - '* background this will be the color we search for and replace with transparency - colorMap.OldColor = LogoColoreTrasparente - colorMap.NewColor = Color.FromArgb(0, 0, 0, 0) - - Dim remapTable As Imaging.ColorMap() = {colorMap} - imageAttributes.SetRemapTable(remapTable, Imaging.ColorAdjustType.Bitmap) - - '* The second color manipulation is used to change the opacity by setting the 3rd row and 3rd column to 0.3f - Dim colorMatrixElements As Single()() = {New Single() {1.0F, 0.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 1.0F, 0.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 1.0F, 0.0F, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, CType(_LogoTrasparenza, Single) / 100, 0.0F}, New Single() {0.0F, 0.0F, 0.0F, 0.0F, 1.0F}} - Dim wmColorMatrix As Imaging.ColorMatrix = New Imaging.ColorMatrix(colorMatrixElements) - imageAttributes.SetColorMatrix(wmColorMatrix, Imaging.ColorMatrixFlag.Default, Imaging.ColorAdjustType.Bitmap) - - Dim FotoLogoH As Integer = _LogoAltezza - Dim FotoLogoW As Integer = _LogoLarghezza - Dim FattoreAlt As Double = ImmagineLogo.Height / FotoLogoH - Dim FattoreLarg As Double = ImmagineLogo.Width / FotoLogoW - Dim NuovaSize As Size - If FattoreLarg > FattoreAlt Then - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoW, "Larghezza") - Else - NuovaSize = NewthumbSize(ImmagineLogo.Width, ImmagineLogo.Height, FotoLogoH, "Altezza") - End If - - Dim MargineUsato As Integer - Dim MargineL As Integer - Dim InPercentualeL As Boolean - If _LogoMargine.EndsWith("%") = True Then - InPercentualeL = True - Else - InPercentualeL = False - End If - MargineL = CType(Val(_LogoMargine), Integer) - If InPercentualeL = True Then - MargineUsato = CType(imgOutputBig.Height * MargineL / 100, Integer) - Else - MargineUsato = MargineL - End If - - Dim xPosOfWm As Integer - Dim yPosOfWm As Integer - Select Case _LogoPosizioneH.ToUpper - Case "SINISTRA", "NESSUNA" - xPosOfWm = MargineUsato - - Case "CENTRO" - xPosOfWm = CType((imgOutputBig.Width - NuovaSize.Width) / 2, Integer) - - Case "DESTRA" - xPosOfWm = ((imgOutputBig.Width - NuovaSize.Width) - MargineUsato) - End Select - Select Case _LogoPosizioneV.ToUpper - Case "ALTO", "NESSUNA" - yPosOfWm = MargineUsato - - Case "CENTRO" - yPosOfWm = CType((imgOutputBig.Height - NuovaSize.Height) / 2, Integer) - - Case "BASSO" - yPosOfWm = ((imgOutputBig.Height - NuovaSize.Height) - MargineUsato) - End Select - - grWatermark.DrawImage(ImmagineLogo, New Rectangle(xPosOfWm, yPosOfWm, NuovaSize.Width, NuovaSize.Height), 0, 0, ImmagineLogo.Width, ImmagineLogo.Height, GraphicsUnit.Pixel, imageAttributes) - grWatermark.Dispose() - End If - End Sub - - - Private Sub salvaFoto(imgOutputBig As Bitmap, thumbSizeBig As Size, NomeFileBig As String, NomeFileSmall As String, thumbSizeSmall As Size) - - If _FotoGrandeDimOrigina = False Then - 'attenzione non controlla se è png - 'imgOutputBig.Save(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig, Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig), jpegQuality) - - Dim g2 As System.Drawing.Image = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - If g2.Width > g2.Height Then - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _LarghezzaBig, "Larghezza") - Else - thumbSizeBig = NewthumbSize(g2.Width, g2.Height, _AltezzaBig, "Altezza") - End If - Dim imgOutputBig2 As New Bitmap(g2, thumbSizeBig.Width, thumbSizeBig.Height) - 'imgOutputBig2.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig2, Path.Combine(_DestDir.FullName, NomeFileBig), jpegQuality) - 'imgOutputBig2.Dispose() - 'imgOutputBig.Dispose() - g2.Dispose() - Else - 'imgOutputBig.Save(Path.Combine(_DestDir.FullName, NomeFileBig), thisFormat) - salvaImmagineCustomQuality(imgOutputBig, Path.Combine(_DestDir.FullName, NomeFileBig), jpegQuality) - imgOutputBig.Dispose() - End If - - - If _CreaMiniature Then - If _AggiungiScritteMiniature = True Then - Dim g1 As System.Drawing.Image - If _FotoGrandeDimOrigina = False Then - g1 = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - Else - g1 = System.Drawing.Image.FromFile(Path.Combine(_DestDir.FullName, NomeFileBig)) - End If - Dim imgOutputSmall As New Bitmap(g1, thumbSizeSmall.Width, thumbSizeSmall.Height) - If _DirectorySorgente.ToUpper = _DirectoryDestinazione.ToUpper Then - NomeFileSmall = NomeFileSmall.Substring(0, NomeFileSmall.Length - 4) & Codice & NomeFileSmall.Substring(NomeFileSmall.Length - 4) - End If - 'imgOutputSmall.Save(Path.Combine(_DestDir.FullName, NomeFileSmall), thisFormat) - salvaImmagineCustomQuality(imgOutputSmall, Path.Combine(_DestDir.FullName, NomeFileSmall), jpegQualityMin) - 'imgOutputSmall.Dispose() - g1.Dispose() - End If - - - - End If - - If File.Exists(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) = True Then - Kill(Path.Combine(_DestDir.FullName, "Temp_" & NomeFileBig)) - End If - - - End Sub - - Private Sub salvaImmagineCustomQuality(imageToSave As Bitmap, nomeFileFinale As String, quality As Long) - - Dim JgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg) - Dim MyEncoder As Encoder = Encoder.Quality - - Dim MyEncoderParameters As New EncoderParameters(1) - - Dim MyEncoderParameter As New EncoderParameter(MyEncoder, jpegQuality) - MyEncoderParameters.Param(0) = MyEncoderParameter - imageToSave.Save(nomeFileFinale, JgpEncoder, MyEncoderParameters) - imageToSave.Dispose() - End Sub - - - - Private Function GetEncoder(ByVal format As ImageFormat) As ImageCodecInfo - - Dim codecs As ImageCodecInfo() = ImageCodecInfo.GetImageDecoders() - - Dim codec As ImageCodecInfo - For Each codec In codecs - If codec.FormatID = format.Guid Then - Return codec - End If - Next codec - Return Nothing - - End Function - - - - - - - ''' - ''' Calculate the Size of the New image - ''' - ''' Larghezza - ''' Altezza - ''' - ''' - ''' - ''' - Function NewthumbSize(ByVal currentwidth As Integer, ByVal currentheight As Integer, ByVal MaxPixel As Integer, ByVal TipoSize As String) As Size - ' e - '*** Larghezza, Altezza, Auto - - Dim tempMultiplier As Double - - If TipoSize.ToUpper = "Larghezza".ToUpper Then - tempMultiplier = MaxPixel / currentwidth - ElseIf TipoSize.ToUpper = "Altezza".ToUpper Then - tempMultiplier = MaxPixel / currentheight - Else - If currentheight > currentwidth Then ' portrait - tempMultiplier = MaxPixel / currentheight - Else - tempMultiplier = MaxPixel / currentwidth - End If - End If - - Dim NewSize As New Size(CInt(currentwidth * tempMultiplier), CInt(currentheight * tempMultiplier)) - - Return NewSize - End Function - - - - - Public Property DirectorySorgente() As String - Get - Return _DirectorySorgente - End Get - Set(ByVal value As String) - _DirectorySorgente = value - End Set - End Property - - Public Property DirectoryDestinazione() As String - Get - Return _DirectoryDestinazione - End Get - Set(ByVal value As String) - _DirectoryDestinazione = value - End Set - End Property - - - Public Property SourceDir() As DirectoryInfo - Get - Return _SourceDir - End Get - Set(ByVal value As DirectoryInfo) - _SourceDir = value - End Set - End Property - - Public Property DestDirStart() As DirectoryInfo - Get - Return _DestDirStart - End Get - Set(ByVal value As DirectoryInfo) - _DestDirStart = value - End Set - End Property - - - - Public Property TestoFirmaStart() As String - Get - Return _TestoFirmaStart - End Get - Set(ByVal value As String) - _TestoFirmaStart = value - End Set - End Property - - Public Property TestoFirmaStartV() As String - Get - Return _TestoFirmaStartV - End Get - - Set(ByVal value As String) - _TestoFirmaStartV = value - End Set - End Property - - Public Property DataPartenza() As DateTime - Get - Return _DataPartenza - End Get - Set(ByVal value As DateTime) - _DataPartenza = value - End Set - End Property - - Public Property TestoOrario() As String - Get - Return _TestoOrario - End Get - Set(ByVal value As String) - _TestoOrario = value - End Set - End Property - - Public Property DimStandard() As Integer - Get - Return _DimStandard - End Get - Set(ByVal value As Integer) - _DimStandard = value - End Set - End Property - - Public Property DimStandardMiniatura() As Integer - Get - Return _DimStandardMiniatura - End Get - Set(ByVal value As Integer) - _DimStandardMiniatura = value - End Set - End Property - - Public Property NomeData() As Boolean - Get - Return _NomeData - End Get - Set(ByVal value As Boolean) - _NomeData = value - End Set - End Property - - Public Property TestoNome() As Boolean - Get - Return _TestoNome - End Get - Set(ByVal value As Boolean) - _TestoNome = value - End Set - End Property - - Public Property UsaOrarioMiniatura() As Boolean - Get - Return _UsaOrarioMiniatura - End Get - Set(ByVal value As Boolean) - _UsaOrarioMiniatura = value - End Set - End Property - - Public Property UsaOrarioTestoApplicare() As Boolean - Get - Return _UsaOrarioTestoApplicare - End Get - Set(ByVal value As Boolean) - _UsaOrarioTestoApplicare = value - End Set - End Property - - Public Property UsaTempoGaraTestoApplicare() As Boolean - Get - Return _UsaTempoGaraTestoApplicare - End Get - Set(ByVal value As Boolean) - _UsaTempoGaraTestoApplicare = value - End Set - End Property - - Public Property UsaRotazioneAutomatica() As Boolean - Get - Return _UsaRotazioneAutomatica - End Get - Set(ByVal value As Boolean) - _UsaRotazioneAutomatica = value - End Set - End Property - - Public Property UsaForzaJpg() As Boolean - Get - Return _UsaForzaJpg - End Get - Set(ByVal value As Boolean) - _UsaForzaJpg = value - End Set - End Property - - - - Public Property LarghezzaSmall() As Integer - Get - Return _LarghezzaSmall - End Get - Set(ByVal value As Integer) - _LarghezzaSmall = value - End Set - End Property - - Public Property AltezzaSmall() As Integer - Get - Return _AltezzaSmall - End Get - Set(ByVal value As Integer) - _AltezzaSmall = value - End Set - End Property - - - Public Property CreaMiniature() As Boolean - Get - Return _CreaMiniature - End Get - Set(ByVal value As Boolean) - _CreaMiniature = value - End Set - End Property - - Public Property AggiungiScritteMiniature() As Boolean - Get - Return _AggiungiScritteMiniature - End Get - Set(ByVal value As Boolean) - _AggiungiScritteMiniature = value - End Set - End Property - - Public Property NomeFileChild() As String - Get - Return _NomeFileChild - End Get - Set(ByVal value As String) - _NomeFileChild = value - End Set - End Property - - Public Property Suffisso() As String - Get - Return _Suffisso - End Get - Set(ByVal value As String) - _Suffisso = value - End Set - End Property - - Public Property Codice() As String - Get - Return _Codice - End Get - Set(ByVal value As String) - _Codice = value - End Set - End Property - - - Public Property Trasparenza() As Integer - Get - Return _Trasparenza - End Get - Set(ByVal value As Integer) - _Trasparenza = value - End Set - End Property - - Public Property IlFont() As String - Get - Return _IlFont - End Get - Set(ByVal value As String) - _IlFont = value - End Set - End Property - - Public Property Grassetto() As Boolean - Get - Return _Grassetto - End Get - Set(ByVal value As Boolean) - _Grassetto = value - End Set - End Property - - Public Property Posizione() As String - Get - Return _Posizione - End Get - Set(ByVal value As String) - _Posizione = value - End Set - End Property - - Public Property Allineamento() As String - Get - Return _Allineamento - End Get - Set(ByVal value As String) - _Allineamento = value - End Set - End Property - - Public Property Margine() As Integer - Get - Return _Margine - End Get - Set(ByVal value As Integer) - _Margine = value - End Set - End Property - - Public Property LogoAltezza() As Integer - Get - Return _LogoAltezza - End Get - Set(ByVal value As Integer) - _LogoAltezza = value - End Set - End Property - - Public Property LogoLarghezza() As Integer - Get - Return _LogoLarghezza - End Get - Set(ByVal value As Integer) - _LogoLarghezza = value - End Set - End Property - - Public Property FontColoreR() As Integer - Get - Return _FontColoreR - End Get - Set(ByVal value As Integer) - _FontColoreR = value - End Set - End Property - - Public Property FontColoreG() As Integer - Get - Return _FontColoreG - End Get - Set(ByVal value As Integer) - _FontColoreG = value - End Set - End Property - - Public Property FontColoreB() As Integer - Get - Return _FontColoreB - End Get - Set(ByVal value As Integer) - _FontColoreB = value - End Set - End Property - - Public Property fontColoreRGB() As Color - Get - Return _fontColoreRGB - End Get - Set(ByVal value As Color) - _fontColoreRGB = value - End Set - End Property - - Public Property LogoAggiungi() As Boolean - Get - Return _LogoAggiungi - End Get - Set(ByVal value As Boolean) - _LogoAggiungi = value - End Set - End Property - - Public Property LogoNomeFile() As String - Get - Return _LogoNomeFile - End Get - Set(ByVal value As String) - _LogoNomeFile = value - End Set - End Property - - Public Property LogoTrasparenza() As String - Get - Return _LogoTrasparenza - End Get - Set(ByVal value As String) - _LogoTrasparenza = value - End Set - End Property - - Public Property LogoMargine() As String - Get - Return _LogoMargine - End Get - Set(ByVal value As String) - _LogoMargine = value - End Set - End Property - - Public Property LogoPosizioneH() As String - Get - Return _LogoPosizioneH - End Get - Set(ByVal value As String) - _LogoPosizioneH = value - End Set - End Property - - Public Property LogoPosizioneV() As String - Get - Return _LogoPosizioneV - End Get - Set(ByVal value As String) - _LogoPosizioneV = value - End Set - End Property - - Public Property FotoGrandeDimOrigina() As Boolean - Get - Return _FotoGrandeDimOrigina - End Get - Set(ByVal value As Boolean) - _FotoGrandeDimOrigina = value - End Set - End Property - - Public Property AltezzaBig() As Integer - Get - Return _AltezzaBig - End Get - Set(ByVal value As Integer) - _AltezzaBig = value - End Set - End Property - - Public Property LarghezzaBig() As Integer - Get - Return _LarghezzaBig - End Get - Set(ByVal value As Integer) - _LarghezzaBig = value - End Set - End Property - - Public Property DestDir() As DirectoryInfo - Get - Return _DestDir - End Get - Set(ByVal value As DirectoryInfo) - _DestDir = value - End Set - End Property - - Public Property DimVert() As Integer - Get - Return _DimVert - - End Get - Set(ByVal value As Integer) - _DimVert = value - - End Set - End Property - - Public Property MargVert() As Integer - Get - Return _MargVert - - End Get - Set(ByVal value As Integer) - _MargVert = value - End Set - End Property - - Public Property TestoMin() As Boolean - Get - Return _TestoMin - - End Get - Set(ByVal value As Boolean) - _TestoMin = value - - End Set - End Property - - Public Property DimMin() As Integer - Get - Return _DimMin - - End Get - Set(ByVal value As Integer) - _DimMin = value - - End Set - End Property - - Public Property SecretDefault() As Boolean - Get - Return _SecretDefault - - End Get - Set(ByVal value As Boolean) - _SecretDefault = value - - End Set - End Property - - Public Property SecretBig() As Boolean - Get - Return _SecretBig - - End Get - Set(ByVal value As Boolean) - _SecretBig = value - - End Set - End Property - - Public Property SecretSmall() As Boolean - Get - Return _SecretSmall - - End Get - Set(ByVal value As Boolean) - _SecretSmall = value - - End Set - End Property - - Public Property SecretPathSmall() As String - Get - Return _SecretPathSmall - - End Get - Set(ByVal value As String) - _SecretPathSmall = value - - End Set - End Property - - Public Property SecretPathBig() As String - Get - Return _SecretPathBig - - End Get - Set(ByVal value As String) - _SecretPathBig = value - - End Set - End Property - - Public Property AggTempoGaraMin() As Boolean - Get - Return _AggTempoGaraMin - - End Get - Set(ByVal value As Boolean) - _AggTempoGaraMin = value - - End Set - End Property - - Public Property AggNumTempMin() As Boolean - Get - Return _AggNumTempMin - - End Get - Set(ByVal value As Boolean) - _AggNumTempMin = value - - End Set - End Property - - Public Property jpegQuality() As Long - Get - Return _jpegQuality - End Get - Set(ByVal value As Long) - _jpegQuality = value - End Set - - End Property - - Public Property jpegQualityMin() As Long - Get - Return _jpegQualityMin - End Get - Set(ByVal value As Long) - _jpegQualityMin = value - End Set - - End Property - -End Class diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index bc94a4c..e71f7cd 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -65,12 +65,23 @@ namespace ImageCatalog_2 NotifyPropertyChanged(); } } + + private string _verticalText; + public string VerticalText + { + get => _verticalText; + set + { + _verticalText = value; + NotifyPropertyChanged(); + } + } private bool _uiEnabled = true; public bool UiEnabled { - get { return _uiEnabled; } + get => _uiEnabled; set { _uiEnabled = value; diff --git a/imagecatalog/ExifReader.vb b/imagecatalog/ExifReader.vb deleted file mode 100644 index 15a19bd..0000000 --- a/imagecatalog/ExifReader.vb +++ /dev/null @@ -1,1068 +0,0 @@ -'''----------------------------------------------------------------------------- -''' -''' Utility class for reading EXIF data from images. Provides abstraction -''' for most common data and generic utilities for work with all other. -''' -''' -''' Copyright (c) Michal A. Valášek - Altair Communications, 2003 -''' Copmany: http://software.altaircom.net * support@altaircom.net -''' Private: http://www.rider.cz * developer@rider.cz -''' This is free software licensed under GNU Lesser General Public License -''' -''' -''' [altair] 10.9.2003 Created -''' -'''----------------------------------------------------------------------------- -Public Class ExifReader - Implements IDisposable - - Private Image As System.Drawing.Bitmap - - '''----------------------------------------------------------------------------- - ''' - ''' Contains possible values of EXIF tag names (ID) - ''' - ''' See GdiPlusImaging.h - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum TagNames - ExifIFD = &H8769 - GpsIFD = &H8825 - NewSubfileType = &HFE - SubfileType = &HFF - ImageWidth = &H100 - ImageHeight = &H101 - BitsPerSample = &H102 - Compression = &H103 - PhotometricInterp = &H106 - ThreshHolding = &H107 - CellWidth = &H108 - CellHeight = &H109 - FillOrder = &H10A - DocumentName = &H10D - ImageDescription = &H10E - EquipMake = &H10F - EquipModel = &H110 - StripOffsets = &H111 - Orientation = &H112 - SamplesPerPixel = &H115 - RowsPerStrip = &H116 - StripBytesCount = &H117 - MinSampleValue = &H118 - MaxSampleValue = &H119 - XResolution = &H11A - YResolution = &H11B - PlanarConfig = &H11C - PageName = &H11D - XPosition = &H11E - YPosition = &H11F - FreeOffset = &H120 - FreeByteCounts = &H121 - GrayResponseUnit = &H122 - GrayResponseCurve = &H123 - T4Option = &H124 - T6Option = &H125 - ResolutionUnit = &H128 - PageNumber = &H129 - TransferFuncition = &H12D - SoftwareUsed = &H131 - DateTime = &H132 - Artist = &H13B - HostComputer = &H13C - Predictor = &H13D - WhitePoint = &H13E - PrimaryChromaticities = &H13F - ColorMap = &H140 - HalftoneHints = &H141 - TileWidth = &H142 - TileLength = &H143 - TileOffset = &H144 - TileByteCounts = &H145 - InkSet = &H14C - InkNames = &H14D - NumberOfInks = &H14E - DotRange = &H150 - TargetPrinter = &H151 - ExtraSamples = &H152 - SampleFormat = &H153 - SMinSampleValue = &H154 - SMaxSampleValue = &H155 - TransferRange = &H156 - JPEGProc = &H200 - JPEGInterFormat = &H201 - JPEGInterLength = &H202 - JPEGRestartInterval = &H203 - JPEGLosslessPredictors = &H205 - JPEGPointTransforms = &H206 - JPEGQTables = &H207 - JPEGDCTables = &H208 - JPEGACTables = &H209 - YCbCrCoefficients = &H211 - YCbCrSubsampling = &H212 - YCbCrPositioning = &H213 - REFBlackWhite = &H214 - ICCProfile = &H8773 - Gamma = &H301 - ICCProfileDescriptor = &H302 - SRGBRenderingIntent = &H303 - ImageTitle = &H320 - Copyright = &H8298 - ResolutionXUnit = &H5001 - ResolutionYUnit = &H5002 - ResolutionXLengthUnit = &H5003 - ResolutionYLengthUnit = &H5004 - PrintFlags = &H5005 - PrintFlagsVersion = &H5006 - PrintFlagsCrop = &H5007 - PrintFlagsBleedWidth = &H5008 - PrintFlagsBleedWidthScale = &H5009 - HalftoneLPI = &H500A - HalftoneLPIUnit = &H500B - HalftoneDegree = &H500C - HalftoneShape = &H500D - HalftoneMisc = &H500E - HalftoneScreen = &H500F - JPEGQuality = &H5010 - GridSize = &H5011 - ThumbnailFormat = &H5012 - ThumbnailWidth = &H5013 - ThumbnailHeight = &H5014 - ThumbnailColorDepth = &H5015 - ThumbnailPlanes = &H5016 - ThumbnailRawBytes = &H5017 - ThumbnailSize = &H5018 - ThumbnailCompressedSize = &H5019 - ColorTransferFunction = &H501A - ThumbnailData = &H501B - ThumbnailImageWidth = &H5020 - ThumbnailImageHeight = &H502 - ThumbnailBitsPerSample = &H5022 - ThumbnailCompression = &H5023 - ThumbnailPhotometricInterp = &H5024 - ThumbnailImageDescription = &H5025 - ThumbnailEquipMake = &H5026 - ThumbnailEquipModel = &H5027 - ThumbnailStripOffsets = &H5028 - ThumbnailOrientation = &H5029 - ThumbnailSamplesPerPixel = &H502A - ThumbnailRowsPerStrip = &H502B - ThumbnailStripBytesCount = &H502C - ThumbnailResolutionX = &H502D - ThumbnailResolutionY = &H502E - ThumbnailPlanarConfig = &H502F - ThumbnailResolutionUnit = &H5030 - ThumbnailTransferFunction = &H5031 - ThumbnailSoftwareUsed = &H5032 - ThumbnailDateTime = &H5033 - ThumbnailArtist = &H5034 - ThumbnailWhitePoint = &H5035 - ThumbnailPrimaryChromaticities = &H5036 - ThumbnailYCbCrCoefficients = &H5037 - ThumbnailYCbCrSubsampling = &H5038 - ThumbnailYCbCrPositioning = &H5039 - ThumbnailRefBlackWhite = &H503A - ThumbnailCopyRight = &H503B - LuminanceTable = &H5090 - ChrominanceTable = &H5091 - FrameDelay = &H5100 - LoopCount = &H5101 - PixelUnit = &H5110 - PixelPerUnitX = &H5111 - PixelPerUnitY = &H5112 - PaletteHistogram = &H5113 - ExifExposureTime = &H829A - ExifFNumber = &H829D - ExifExposureProg = &H8822 - ExifSpectralSense = &H8824 - ExifISOSpeed = &H8827 - ExifOECF = &H8828 - ExifVer = &H9000 - ExifDTOrig = &H9003 - ExifDTDigitized = &H9004 - ExifCompConfig = &H9101 - ExifCompBPP = &H9102 - ExifShutterSpeed = &H9201 - ExifAperture = &H9202 - ExifBrightness = &H9203 - ExifExposureBias = &H9204 - ExifMaxAperture = &H9205 - ExifSubjectDist = &H9206 - ExifMeteringMode = &H9207 - ExifLightSource = &H9208 - ExifFlash = &H9209 - ExifFocalLength = &H920A - ExifMakerNote = &H927C - ExifUserComment = &H9286 - ExifDTSubsec = &H9290 - ExifDTOrigSS = &H9291 - ExifDTDigSS = &H9292 - ExifFPXVer = &HA000 - ExifColorSpace = &HA001 - ExifPixXDim = &HA002 - ExifPixYDim = &HA003 - ExifRelatedWav = &HA004 - ExifInterop = &HA005 - ExifFlashEnergy = &HA20B - ExifSpatialFR = &HA20C - ExifFocalXRes = &HA20E - ExifFocalYRes = &HA20F - ExifFocalResUnit = &HA210 - ExifSubjectLoc = &HA214 - ExifExposureIndex = &HA215 - ExifSensingMethod = &HA217 - ExifFileSource = &HA300 - ExifSceneType = &HA301 - ExifCfaPattern = &HA302 - GpsVer = &H0 - GpsLatitudeRef = &H1 - GpsLatitude = &H2 - GpsLongitudeRef = &H3 - GpsLongitude = &H4 - GpsAltitudeRef = &H5 - GpsAltitude = &H6 - GpsGpsTime = &H7 - GpsGpsSatellites = &H8 - GpsGpsStatus = &H9 - GpsGpsMeasureMode = &HA - GpsGpsDop = &HB - GpsSpeedRef = &HC - GpsSpeed = &HD - GpsTrackRef = &HE - GpsTrack = &HF - GpsImgDirRef = &H10 - GpsImgDir = &H11 - GpsMapDatum = &H12 - GpsDestLatRef = &H13 - GpsDestLat = &H14 - GpsDestLongRef = &H15 - GpsDestLong = &H16 - GpsDestBearRef = &H17 - GpsDestBear = &H18 - GpsDestDistRef = &H19 - GpsDestDist = &H1A - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Real position of 0th row and column of picture - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum Orientations - TopLeft = 1 - TopRight = 2 - BottomRight = 3 - BottomLeft = 4 - LeftTop = 5 - RightTop = 6 - RightBottom = 7 - LftBottom = 8 - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Exposure programs - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum ExposurePrograms - Manual = 1 - Normal = 2 - AperturePriority = 3 - ShutterPriority = 4 - Creative = 5 - Action = 6 - Portrait = 7 - Landscape = 8 - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Exposure metering modes - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum ExposureMeteringModes - Unknown = 0 - Average = 1 - CenterWeightedAverage = 2 - Spot = 3 - MultiSpot = 4 - MultiSegment = 5 - [Partial] = 6 - Other = 255 - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Flash activity modes - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum FlashModes - NotFired = 0 - Fired = 1 - FiredButNoStrobeReturned = 5 - FiredAndStrobeReturned = 7 - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Possible light sources (white balance) - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Enum LightSources - Unknown = 0 - Daylight = 1 - Fluorescent = 2 - Tungsten = 3 - Flash = 10 - StandardLightA = 17 - StandardLightB = 18 - StandardLightC = 19 - D55 = 20 - D65 = 21 - D75 = 22 - Other = 255 - End Enum - - '''----------------------------------------------------------------------------- - ''' - ''' Represents rational which is type of some Exif properties - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Structure Rational - Dim Numerator As Int32 - Dim Denominator As Int32 - - '''----------------------------------------------------------------------------- - ''' - ''' Converts rational to string representation - ''' - ''' Optional, default "/". String to be used as delimiter of components. - ''' String representation of the rational. - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Shadows Function ToString(Optional ByVal Delimiter As String = "/") As String - Return Numerator & Delimiter & Denominator - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Converts rational to double precision real number - ''' - ''' The rational as double precision real number. - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Function ToDouble() As Double - Return Numerator / Denominator - End Function - End Structure - - '''----------------------------------------------------------------------------- - ''' - ''' Initializes new instance of this class. - ''' - ''' Bitmap to read exif information from - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Sub New(ByVal Bitmap As System.Drawing.Bitmap) - If Bitmap Is Nothing Then Throw New ArgumentNullException("Bitmap") - Me.Image = Bitmap - End Sub - - '''----------------------------------------------------------------------------- - ''' - ''' Returns all available data in formatted string form - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Overrides Function ToString() As String - Dim SB As New System.Text.StringBuilder - - SB.Append("Image:") - SB.Append("\n\tDimensions: " & Me.Width & " x " & Me.Height & " px") - SB.Append("\n\tResolution: " & Me.ResolutionX & " x " & Me.ResolutionY & " dpi") - SB.Append("\n\tOrientation: " & [Enum].GetName(GetType(Orientations), Me.Orientation)) - SB.Append("\n\tTitle: " & Me.Title) - SB.Append("\n\tDescription: " & Me.Description) - SB.Append("\n\tCopyright: " & Me.Copyright) - SB.Append("\nEquipment:") - SB.Append("\n\tMaker: " & Me.EquipmentMaker) - SB.Append("\n\tModel: " & Me.EquipmentModel) - SB.Append("\n\tSoftware: " & Me.Software) - SB.Append("\nDate and time:") - SB.Append("\n\tGeneral: " & Me.DateTimeLastModified.ToString()) - SB.Append("\n\tOriginal: " & Me.DateTimeOriginal.ToString()) - SB.Append("\n\tDigitized: " & Me.DateTimeDigitized.ToString()) - SB.Append("\nShooting conditions:") - SB.Append("\n\tExposure time: " & Me.ExposureTime.ToString("N4") & " s") - SB.Append("\n\tExposure program: " & [Enum].GetName(GetType(ExposurePrograms), Me.ExposureProgram)) - SB.Append("\n\tExposure mode: " & [Enum].GetName(GetType(ExposureMeteringModes), Me.ExposureMeteringMode)) - SB.Append("\n\tAperture: F" & Me.Aperture.ToString("N2")) - SB.Append("\n\tISO sensitivity: " & Me.ISO) - SB.Append("\n\tSubject distance: " & Me.SubjectDistance.ToString("N2") & " m") - SB.Append("\n\tFocal length: " & Me.FocalLength) - SB.Append("\n\tFlash: " & [Enum].GetName(GetType(FlashModes), Me.FlashMode)) - SB.Append("\n\tLight source (WB): " & [Enum].GetName(GetType(LightSources), Me.LightSource)) - SB.Append("\n\nCopyright (c) Michal A. Valasek - Altair Communications, 2003") - SB.Append("\nhttp://software.altaircom.net * support@altaircom.net") - - SB.Replace("\n", vbCrLf) - SB.Replace("\t", vbTab) - Return SB.ToString() - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Brand of equipment (EXIF EquipMake) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property EquipmentMaker() As String - Get - Return Me.GetPropertyString(TagNames.EquipMake) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Model of equipment (EXIF EquipModel) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property EquipmentModel() As String - Get - Return Me.GetPropertyString(TagNames.EquipModel) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Software used for processing (EXIF Software) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Software() As String - Get - Return Me.GetPropertyString(TagNames.SoftwareUsed) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Orientation of image (position of row 0, column 0) (EXIF Orientation) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Orientation() As Orientations - Get - Dim X As Int32 = Me.GetPropertyInt16(TagNames.Orientation) - - If Not [Enum].IsDefined(GetType(Orientations), X) Then - Return Orientations.TopLeft - Else - Return CType([Enum].Parse(GetType(Orientations), [Enum].GetName(GetType(Orientations), X)), Orientations) - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Time when image was last modified (EXIF DateTime). - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property DateTimeLastModified() As DateTime - Get - Try - Return DateTime.ParseExact(Me.GetPropertyString(TagNames.DateTime), "yyyy\:MM\:dd HH\:mm\:ss", Nothing) - Catch ex As Exception - Return DateTime.MinValue - End Try - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Time when image was taken (EXIF DateTimeOriginal). - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property DateTimeOriginal() As DateTime - Get - Try - Return DateTime.ParseExact(Me.GetPropertyString(TagNames.ExifDTOrig), "yyyy\:MM\:dd HH\:mm\:ss", Nothing) - Catch ex As Exception - Return DateTime.MinValue - End Try - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Time when image was digitized (EXIF DateTimeDigitized). - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property DateTimeDigitized() As DateTime - Get - Try - Return DateTime.ParseExact(Me.GetPropertyString(TagNames.ExifDTDigitized), "yyyy\:MM\:dd HH\:mm\:ss", Nothing) - Catch ex As Exception - Return DateTime.MinValue - End Try - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Image width - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Width() As Int16 - Get - Return Me.GetPropertyInt16(TagNames.ImageWidth) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Image height - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Height() As Int16 - Get - Return Me.GetPropertyInt16(TagNames.ImageHeight) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' X resolution in dpi (EXIF XResolution/ResolutionUnit) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ResolutionX() As Double - Get - Dim R As Double = Me.GetPropertyRational(TagNames.XResolution).ToDouble() - - If Me.GetPropertyInt16(TagNames.ResolutionUnit) = 3 Then - '-- resolution is in points/cm - Return R * 2.54 - Else - '-- resolution is in points/inch - Return R - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Y resolution in dpi (EXIF YResolution/ResolutionUnit) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ResolutionY() As Double - Get - Dim R As Double = Me.GetPropertyRational(TagNames.YResolution).ToDouble() - - If Me.GetPropertyInt16(TagNames.ResolutionUnit) = 3 Then - '-- resolution is in points/cm - Return R * 2.54 - Else - '-- resolution is in points/inch - Return R - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Image title (EXIF ImageTitle) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Title() As String - Get - Return Me.GetPropertyString(TagNames.ImageTitle) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Image description (EXIF ImageDescription) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Description() As String - Get - Return Me.GetPropertyString(TagNames.ImageDescription) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Image copyright (EXIF Copyright) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Copyright() As String - Get - Return Me.GetPropertyString(TagNames.Copyright) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Exposure time in seconds (EXIF ExifExposureTime/ExifShutterSpeed) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ExposureTime() As Double - Get - If Me.IsPropertyDefined(TagNames.ExifExposureTime) Then - '-- Exposure time is explicitly specified - Return Me.GetPropertyRational(TagNames.ExifExposureTime).ToDouble - ElseIf Me.IsPropertyDefined(TagNames.ExifShutterSpeed) Then - '-- Compute exposure time from shutter speed - Return 1 / (2 ^ Me.GetPropertyRational(TagNames.ExifShutterSpeed).ToDouble) - Else - '-- Can't figure out - Return 0 - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Aperture value as F number (EXIF ExifFNumber/ExifApertureValue) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property Aperture() As Double - Get - If Me.IsPropertyDefined(TagNames.ExifFNumber) Then - Return Me.GetPropertyRational(TagNames.ExifFNumber).ToDouble() - ElseIf Me.IsPropertyDefined(TagNames.ExifAperture) Then - Return System.Math.Sqrt(2) ^ Me.GetPropertyRational(TagNames.ExifAperture).ToDouble() - Else - Return 0 - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Exposure program used (EXIF ExifExposureProg) - ''' - ''' - ''' If not specified, returns Normal (2) - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ExposureProgram() As ExposurePrograms - Get - Dim X As Int32 = Me.GetPropertyInt16(TagNames.ExifExposureProg) - - If [Enum].IsDefined(GetType(ExposurePrograms), X) Then - Return CType([Enum].Parse(GetType(ExposurePrograms), [Enum].GetName(GetType(ExposurePrograms), X)), ExposurePrograms) - Else - Return ExposurePrograms.Normal - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' ISO sensitivity - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ISO() As Int16 - Get - Return Me.GetPropertyInt16(TagNames.ExifISOSpeed) - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Subject distance in meters (EXIF SubjectDistance) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property SubjectDistance() As Double - Get - Return Me.GetPropertyRational(TagNames.ExifSubjectDist).ToDouble() - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Exposure method metering mode used (EXIF MeteringMode) - ''' - ''' - ''' If not specified, returns Unknown (0) - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property ExposureMeteringMode() As ExposureMeteringModes - Get - Dim X As Int32 = Me.GetPropertyInt16(TagNames.ExifMeteringMode) - - If [Enum].IsDefined(GetType(ExposureMeteringModes), X) Then - Return CType([Enum].Parse(GetType(ExposureMeteringModes), [Enum].GetName(GetType(ExposureMeteringModes), X)), ExposureMeteringModes) - Else - Return ExposureMeteringModes.Unknown - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Focal length of lenses in mm (EXIF FocalLength) - ''' - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property FocalLength() As Double - Get - Return Me.GetPropertyRational(TagNames.ExifFocalLength).ToDouble - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Flash mode (EXIF Flash) - ''' - ''' - ''' If not present, value NotFired (0) is returned - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property FlashMode() As FlashModes - Get - Dim X As Int32 = Me.GetPropertyInt16(TagNames.ExifFlash) - - If [Enum].IsDefined(GetType(FlashModes), X) Then - Return CType([Enum].Parse(GetType(FlashModes), [Enum].GetName(GetType(FlashModes), X)), FlashModes) - Else - Return FlashModes.NotFired - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Light source / white balance (EXIF LightSource) - ''' - ''' - ''' If not specified, returns Unknown (0). - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public ReadOnly Property LightSource() As LightSources - Get - Dim X As Int32 = Me.GetPropertyInt16(TagNames.ExifLightSource) - - If [Enum].IsDefined(GetType(LightSources), X) Then - Return CType([Enum].Parse(GetType(LightSources), [Enum].GetName(GetType(LightSources), X)), LightSources) - Else - Return LightSources.Unknown - End If - End Get - End Property - - '''----------------------------------------------------------------------------- - ''' - ''' Checks if current image has specified certain property - ''' - ''' - ''' True if image has specified property, False otherwise. - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Function IsPropertyDefined(ByVal PID As Int32) As Boolean - Return CBool([Array].IndexOf(Me.Image.PropertyIdList, PID) > -1) - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Gets specified Int32 property - ''' - ''' Property ID - ''' Optional, default 0. Default value returned if property is not present. - ''' Value of property or DefaultValue if property is not present. - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Function GetPropertyInt32(ByVal PID As Int32, Optional ByVal DefaultValue As Int32 = 0) As Int32 - If Me.IsPropertyDefined(PID) Then - Return GetInt32(Me.Image.GetPropertyItem(PID).Value) - Else - Return DefaultValue - End If - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Gets specified Int16 property - ''' - ''' Property ID - ''' Optional, default 0. Default value returned if property is not present. - ''' Value of property or DefaultValue if property is not present. - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Function GetPropertyInt16(ByVal PID As Int32, Optional ByVal DefaultValue As Int16 = 0) As Int16 - If Me.IsPropertyDefined(PID) Then - Return GetInt16(Me.Image.GetPropertyItem(PID).Value) - Else - Return DefaultValue - End If - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Gets specified string property - ''' - ''' Property ID - ''' Optional, default String.Empty. Default value returned if property is not present. - ''' - ''' Value of property or DefaultValue if property is not present. - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Function GetPropertyString(ByVal PID As Int32, Optional ByVal DefaultValue As String = "") As String - If Me.IsPropertyDefined(PID) Then - Return GetString(Me.Image.GetPropertyItem(PID).Value) - Else - Return DefaultValue - End If - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Gets specified rational property - ''' - ''' Property ID - ''' - ''' Value of property or 0/1 if not present. - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Function GetPropertyRational(ByVal PID As Int32) As Rational - If Me.IsPropertyDefined(PID) Then - Return GetRational(Me.Image.GetPropertyItem(PID).Value) - Else - Dim R As Rational - R.Numerator = 0 - R.Denominator = 1 - Return R - End If - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Reads Int32 from EXIF bytearray. - ''' - ''' EXIF bytearray to process - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Shared Function GetInt32(ByVal B As Byte()) As Int32 - If B.Length < 4 Then Throw New ArgumentException("Data too short (4 bytes expected)", "B") - Return B(3) << 24 Or B(2) << 16 Or B(1) << 8 Or B(0) - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Reads Int16 from EXIF bytearray. - ''' - ''' EXIF bytearray to process - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Shared Function GetInt16(ByVal B As Byte()) As Int16 - If B.Length < 2 Then Throw New ArgumentException("Data too short (2 bytes expected)", "B") - Return B(1) << 8 Or B(0) - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Reads string from EXIF bytearray. - ''' - ''' EXIF bytearray to process - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Shared Function GetString(ByVal B As Byte()) As String - Dim R As String = System.Text.Encoding.ASCII.GetString(B) - If R.EndsWith(vbNullChar) Then R = R.Substring(0, R.Length - 1) - Return R - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Reads rational from EXIF bytearray. - ''' - ''' EXIF bytearray to process - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Shared Function GetRational(ByVal B As Byte()) As Rational - Dim R As New Rational, N(3), D(3) As Byte - Array.Copy(B, 0, N, 0, 4) - Array.Copy(B, 4, D, 0, 4) - R.Denominator = GetInt32(D) - R.Numerator = GetInt32(N) - Return R - End Function - - '''----------------------------------------------------------------------------- - ''' - ''' Disposes unmanaged resources of this class - ''' - ''' - ''' - ''' [altair] 10.9.2003 Created - ''' - '''----------------------------------------------------------------------------- - Public Sub Dispose() Implements System.IDisposable.Dispose - Me.Image.Dispose() - End Sub -End Class diff --git a/imagecatalog/FileHelper.vb b/imagecatalog/FileHelper.vb deleted file mode 100644 index d8b9f3d..0000000 --- a/imagecatalog/FileHelper.vb +++ /dev/null @@ -1,252 +0,0 @@ -Imports System.Collections.Concurrent -Imports System.IO -Imports System.Collections.Generic -Imports MaddoShared - -Public Class FileHelper - 'Private dirSourceDest As Dictionary(Of FileInfo, DirectoryInfo) - Private filesPerFolder As Integer - Private suffix As String - Private counterSize As Integer - Private numerationType As Integer - Private filter As String - Private separateFiles As Boolean - Private extensions As String = "*.jpg,*.png,*.gif" - - - Public Enum numerazione - Progressiva - Files - End Enum - ''' - ''' Preparazione per la separazione - ''' - ''' - ''' - ''' - ''' - ''' - Public Sub New(ByVal filesPerFolder As Integer, ByVal suffix As String, ByVal counterSize As Integer, ByVal numerationType As Integer) - Me.filesPerFolder = filesPerFolder - Me.suffix = suffix - Me.counterSize = counterSize - Me.numerationType = numerationType - Me.separateFiles = True - End Sub - - ''' - ''' nessuna separazione - ''' - ''' - Public Sub New() - Me.separateFiles = False - End Sub - - - Public Function GetFilesRecursive(ByVal root As DirectoryInfo, ByVal destRoot As DirectoryInfo, ByVal filter As String) As Dictionary(Of FileInfo, DirectoryInfo) - Dim dirSourceDest As New Dictionary(Of FileInfo, DirectoryInfo) - Dim result As New List(Of FileInfo) - - 'Dim stack As New Stack(Of DirectoryInfo) - Dim stack As New Stack(Of KeyValuePair(Of DirectoryInfo, DirectoryInfo)) - - - Me.filter = filter - Dim pair As New KeyValuePair(Of DirectoryInfo, DirectoryInfo) - - - 'stack.Push(root) - stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(root, destRoot)) - - Do While (stack.Count > 0) - Dim curDirKV As KeyValuePair(Of DirectoryInfo, DirectoryInfo) = stack.Pop - 'curDirKP = stack.Pop() - Dim dir As DirectoryInfo = curDirKV.Key - Dim dDir As DirectoryInfo = curDirKV.Value - Try - 'result.AddRange(dir.GetFiles(filter, SearchOption.TopDirectoryOnly)) - ' dividere file qui - If filesPerFolder > 0 And separateFiles Then - appendDictionary(dirSourceDest, dividiFilesInDir(dir, dDir)) - Else - appendDictionary(dirSourceDest, getAllFilesInDir(dir, dDir)) - End If - - - - For Each subDirectory As DirectoryInfo In dir.GetDirectories - stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(subDirectory, New DirectoryInfo(Path.Combine(dDir.FullName, subDirectory.Name)))) - - Next - Catch ex As Exception - Dim e As Exception = ex.Demystify() - Console.WriteLine(e) - Console.WriteLine(e.Message) - Console.WriteLine(e.StackTrace) - End Try - Loop - - Return dirSourceDest - End Function - - 'Public Class FileData - ' Public File As FileInfo - ' Public Directory As DirectoryInfo - ' Public Sub New(newFile As FileInfo, newDirectory As DirectoryInfo) - ' File = newFile - ' Directory = newDirectory - ' End Sub - 'End Class - - 'Public Function GetFilesRecursiveParallel(ByVal root As DirectoryInfo, ByVal destRoot As DirectoryInfo, ByVal filter As String) As List(Of FileData) - - - ' Dim dirSourceDest As New ConcurrentDictionary(Of FileInfo, DirectoryInfo) - ' Dim result As New List(Of FileInfo) - - ' 'Dim stack As New Stack(Of DirectoryInfo) - ' Dim stack As New Stack(Of KeyValuePair(Of DirectoryInfo, DirectoryInfo)) - - - ' Me.filter = filter - ' Dim pair As New KeyValuePair(Of DirectoryInfo, DirectoryInfo) - - - ' 'stack.Push(root) - ' stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(root, destRoot)) - - ' Do While (stack.Count > 0) - ' Dim curDirKV As KeyValuePair(Of DirectoryInfo, DirectoryInfo) = stack.Pop - ' 'curDirKP = stack.Pop() - ' Dim dir As DirectoryInfo = curDirKV.Key - ' Dim dDir As DirectoryInfo = curDirKV.Value - ' Try - ' 'result.AddRange(dir.GetFiles(filter, SearchOption.TopDirectoryOnly)) - ' ' dividere file qui - ' If filesPerFolder > 0 And separateFiles Then - ' AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir)) - ' Else - ' AppendDictionaryConcurrent(dirSourceDest, DividiFilesInDirConcurrent(dir, dDir)) - ' End If - - ' For Each subDirectory As DirectoryInfo In dir.GetDirectories - ' stack.Push(New KeyValuePair(Of DirectoryInfo, DirectoryInfo)(subDirectory, New DirectoryInfo(Path.Combine(dDir.FullName, subDirectory.Name)))) - - ' Next - ' Catch ex As Exception - ' ' TODO: FARE QUALCOSA - ' End Try - ' Loop - - ' Dim resultData As New List(Of FileData) - ' resultData.AddRange(From p In dirSourceDest Select New FileData(p.Key, p.Value)) - ' Return resultData - ' 'Return dirSourceDest - 'End Function - - Public Function appendDictionary(ByVal dictA As Dictionary(Of FileInfo, DirectoryInfo), ByVal dictB As Dictionary(Of FileInfo, DirectoryInfo)) As Dictionary(Of FileInfo, DirectoryInfo) - For Each pair As KeyValuePair(Of FileInfo, DirectoryInfo) In dictB - dictA.Add(pair.Key, pair.Value) - Next - Return dictA - End Function - - 'Public Function AppendDictionaryConcurrent(ByVal dictA As ConcurrentDictionary(Of FileInfo, DirectoryInfo), ByVal dictB As ConcurrentDictionary(Of FileInfo, DirectoryInfo)) As ConcurrentDictionary(Of FileInfo, DirectoryInfo) - ' For Each pair As KeyValuePair(Of FileInfo, DirectoryInfo) In dictB - ' dictA.TryAdd(pair.Key, pair.Value) - ' 'dictA.Add(pair.Key, pair.Value) - ' Next - ' Return dictA - 'End Function - - Public Function getAllFilesInDir(dir As DirectoryInfo, dirDest As DirectoryInfo) As Dictionary(Of FileInfo, DirectoryInfo) - Dim dict As New Dictionary(Of FileInfo, DirectoryInfo) - For Each File As FileInfo In dir.GetFiles(filter) - dict.Add(File, New DirectoryInfo(Path.Combine(dirDest.FullName, File.Name))) - - Next - Return dict - End Function - - Private Function dividiFilesInDir(dir As DirectoryInfo, dirDest As DirectoryInfo) As Dictionary(Of FileInfo, DirectoryInfo) - Dim filesCount As Integer = dir.GetFiles(filter).Count - Dim contaFilePerDir As Integer = 0 - Dim contaDirPerDir As Integer = 0 - Dim tempText As String = String.Empty - Dim foldersDict As New Dictionary(Of FileInfo, DirectoryInfo) - - Dim destDir As DirectoryInfo - destDir = New DirectoryInfo(Path.Combine(dirDest.FullName)) - For Each file As FileInfo In dir.GetFiles(filter) - - contaFilePerDir += 1 - - If contaFilePerDir = (contaDirPerDir * filesPerFolder) + 1 Then - contaDirPerDir += 1 - - If numerationType = numerazione.Progressiva Then - tempText = contaDirPerDir.ToString - Else - tempText = (contaDirPerDir * filesPerFolder).ToString - End If - Dim i As Integer - For i = 1 To (counterSize - tempText.Length) - tempText = "0" & tempText - Next - destDir = New DirectoryInfo(Path.Combine(dirDest.FullName, suffix + tempText)) - - - - End If - - If Not destDir.Exists Then - destDir.Create() - End If - - foldersDict.Add(file, destDir) - Next - - Return foldersDict - End Function - - Private Function DividiFilesInDirConcurrent(dir As DirectoryInfo, dirDest As DirectoryInfo) As ConcurrentDictionary(Of FileInfo, DirectoryInfo) - Dim filesCount As Integer = dir.GetFiles(filter).Count - Dim contaFilePerDir As Integer = 0 - Dim contaDirPerDir As Integer = 0 - Dim tempText As String = String.Empty - Dim foldersDict As New ConcurrentDictionary(Of FileInfo, DirectoryInfo) - - Dim destDir As DirectoryInfo - destDir = New DirectoryInfo(Path.Combine(dirDest.FullName)) - For Each file As FileInfo In dir.GetFiles(filter) - - contaFilePerDir += 1 - - If contaFilePerDir = (contaDirPerDir * filesPerFolder) + 1 Then - contaDirPerDir += 1 - - If numerationType = numerazione.Progressiva Then - tempText = contaDirPerDir.ToString - Else - tempText = (contaDirPerDir * filesPerFolder).ToString - End If - Dim i As Integer - For i = 1 To (counterSize - tempText.Length) - tempText = "0" & tempText - Next - destDir = New DirectoryInfo(Path.Combine(dirDest.FullName, suffix + tempText)) - - - - End If - - If Not destDir.Exists Then - destDir.Create() - End If - - foldersDict.TryAdd(file, destDir) - Next - - Return foldersDict - End Function -End Class diff --git a/imagecatalog/LoadBuffer.cs b/imagecatalog/LoadBuffer.cs deleted file mode 100644 index f116be3..0000000 --- a/imagecatalog/LoadBuffer.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Collections.Generic; -using System.Drawing; -using System.IO; - -namespace ImageCatalog -{ - public class LoadBuffer - { - public List imageList = new List(); - public List picSourceList = new List(); - public List> dirSourceList = new List>(); - } -} \ No newline at end of file diff --git a/imagecatalog/LoadBuffer.vb b/imagecatalog/LoadBuffer.vb deleted file mode 100644 index b59cf11..0000000 --- a/imagecatalog/LoadBuffer.vb +++ /dev/null @@ -1,9 +0,0 @@ -Imports System.Collections.Generic -Imports System.IO - -Public Class LoadBuffer - Public imageList As New List(Of System.Drawing.Image) - Public picSourceList As New List(Of FileInfo) - Public dirSourceList As New List(Of List(Of FileInfo)) - -End Class diff --git a/imagecatalog/MainForm.Designer.cs b/imagecatalog/MainForm.Designer.cs index cb3d6ef..bf1e683 100644 --- a/imagecatalog/MainForm.Designer.cs +++ b/imagecatalog/MainForm.Designer.cs @@ -914,6 +914,7 @@ namespace ImageCatalog // // TextBox29 // + TextBox29.DataBindings.Add(new Binding("Text", bindingSource1, "VerticalText", true, DataSourceUpdateMode.OnPropertyChanged)); TextBox29.Location = new Point(96, 75); TextBox29.Margin = new Padding(4, 5, 4, 5); TextBox29.Multiline = true; diff --git a/imagecatalog/MainForm.cs b/imagecatalog/MainForm.cs index 8430bba..17accea 100644 --- a/imagecatalog/MainForm.cs +++ b/imagecatalog/MainForm.cs @@ -121,8 +121,7 @@ public partial class MainForm // Private ContaFotoCuori As Integer // Private TaskCuori() As PicInfo - - private XYThreadPool MyPool = new XYThreadPool(); + private int ContaImmaginiThread; private int maxThreads = 15; private int minThreads = 5; @@ -375,7 +374,7 @@ public partial class MainForm _parametriSetup.AggiornaParametro("GrandezzaVerticale", TextBox30.Text); _parametriSetup.AggiornaParametro("MargineVerticale", TextBox31.Text); _parametriSetup.AggiornaParametro("DimensioniOriginali", CheckBox15.Checked); - _parametriSetup.AggiornaParametro("TestoVerticale", TextBox29.Text); + _parametriSetup.AggiornaParametro("TestoVerticale", Model.VerticalText); _parametriSetup.AggiornaParametro("NomeMiniatura", RadioButton6.Checked); _parametriSetup.AggiornaParametro("DataFoto", CheckBox16.Checked); _parametriSetup.AggiornaParametro("NumeroFoto", CheckBox17.Checked); @@ -463,7 +462,7 @@ public partial class MainForm TextBox30.Text = _parametriSetup.LeggiParametroString("GrandezzaVerticale"); TextBox31.Text = _parametriSetup.LeggiParametroString("MargineVerticale"); CheckBox15.Checked = _parametriSetup.LeggiParametroBoolean("DimensioniOriginali"); - TextBox29.Text = _parametriSetup.LeggiParametroString("TestoVerticale"); + Model.VerticalText = _parametriSetup.LeggiParametroString("TestoVerticale"); RadioButton6.Checked = _parametriSetup.LeggiParametroBoolean("NomeMiniatura"); CheckBox16.Checked = _parametriSetup.LeggiParametroBoolean("DataFoto"); CheckBox17.Checked = _parametriSetup.LeggiParametroBoolean("NumeroFoto"); @@ -535,7 +534,7 @@ public partial class MainForm } _picSettings.TestoFirmaStart = Model.HorizontalText; - _picSettings.TestoFirmaStartV = TextBox29.Text; + _picSettings.TestoFirmaStartV = Model.VerticalText; _picSettings.DataPartenza = DateTimePicker1.Value; _picSettings.TestoOrario = TextBox18.Text; _picSettings.AltezzaSmall = int.Parse(TextBox6.Text); diff --git a/imagecatalog/ParametriSetup.vb b/imagecatalog/ParametriSetup.vb deleted file mode 100644 index aca5993..0000000 --- a/imagecatalog/ParametriSetup.vb +++ /dev/null @@ -1,167 +0,0 @@ -Imports System.IO - -Public Class ParametriSetup - - - Private _ElencoParametri As DataSet - Private _NomeFileSetup As String - - Public Sub New(ByVal FileSetup As String) - _ElencoParametri = New DataSet - _NomeFileSetup = FileSetup - - If FileSetup <> "" Then - CaricaParametriSetup() - End If - End Sub - - Public Sub New() - _ElencoParametri = New DataSet - _NomeFileSetup = "" - End Sub - - Public Sub CaricaParametriSetup() - _ElencoParametri = LeggiXmlDataSet("Setup", _NomeFileSetup, "Nome") - End Sub - - public sub CaricaParametriSetupStream(ByVal stream As Stream) - _ElencoParametri = LeggiXmlDataSetStream("Setup", stream, "Nome") - End sub - - Public Sub SalvaParametriSetup() - If System.IO.File.Exists(_NomeFileSetup) = True Then - Kill(_NomeFileSetup) - End If - _ElencoParametri.WriteXml(_NomeFileSetup) - End Sub - - Public Function LeggiParametroString(ByVal NomeParametro As String) As String - Dim Risposta As String = "" - - Try - Dim LElenco As DataRow() = _ElencoParametri.Tables("Setup").Select("Nome='" & NomeParametro & "'") - - Dim LaRiga As DataRow - For Each LaRiga In LElenco - Risposta = LaRiga("Valore").ToString - Next - Catch - Risposta = "" - End Try - - Return Risposta - End Function - - Public Function LeggiParametroBoolean(ByVal NomeParametro As String) As Boolean - Dim Risposta As String = "" - - Try - Dim LElenco As DataRow() = _ElencoParametri.Tables("Setup").Select("Nome='" & NomeParametro & "'") - - Dim LaRiga As DataRow - For Each LaRiga In LElenco - Risposta = LaRiga("Valore").ToString - Next - Catch - Risposta = "" - End Try - - Select Case Risposta.ToUpper - Case "TRUE", "OK", "SI", "1", "YES", "VERO" - Return True - Case Else - Return False - End Select - End Function - - Public Sub AggiornaParametro(ByVal NomeParametro As String, ByVal ValoreParametro As Object) - Try - If _ElencoParametri.Tables("Setup") Is Nothing Then - Dim TabellaTmp As New DataTable("Setup") - Dim RigaTmp As DataRow - - Dim LaColonna As DataColumn - LaColonna = TabellaTmp.Columns.Add("Nome", System.Type.GetType("System.String")) - LaColonna = TabellaTmp.Columns.Add("Valore", System.Type.GetType("System.String")) - - '* Aggiunge alla tabella tutte le righe - RigaTmp = TabellaTmp.NewRow - RigaTmp("Nome") = NomeParametro - RigaTmp("Valore") = ValoreParametro - TabellaTmp.Rows.Add(RigaTmp) - - _ElencoParametri.Tables.Add(TabellaTmp) - Else - Dim LElenco As DataRow() = _ElencoParametri.Tables("Setup").Select("Nome='" & NomeParametro & "'") - - If LElenco.Length = 0 Then - Dim LaRiga As DataRow - LaRiga = _ElencoParametri.Tables("Setup").NewRow - LaRiga("Nome") = NomeParametro - LaRiga("Valore") = ValoreParametro - _ElencoParametri.Tables("Setup").Rows.Add(LaRiga) - Else - LElenco(0).Item("Valore") = ValoreParametro - End If - End If - Catch - - End Try - End Sub - - - Private Function LeggiXmlDataTable(ByVal NomeTabella As String, ByVal NomeFileXml As String, Optional ByVal NomeColonnaChiave As String = "") As DataTable - '* Crea e Legge il dataset dal file xml - Dim DataSetXml As New System.Data.DataSet - DataSetXml.ReadXml(NomeFileXml) - - '* Aggiunge il campo chiave - If NomeColonnaChiave <> "" Then - DataSetXml.Tables(NomeTabella).Constraints.Add(NomeColonnaChiave, DataSetXml.Tables(NomeTabella).Columns(NomeColonnaChiave), True) - End If - - '* Restituisce la risposta - Return DataSetXml.Tables(NomeTabella) - End Function - - Private Shared Function LeggiXmlDataSetStream(ByVal NomeTabella As String, ByVal stream As Stream, Optional ByVal NomeColonnaChiave As String = "") As DataSet - '* Crea e Legge il dataset dal file xml - Dim DataSetXml As New System.Data.DataSet - 'DataSetXml.ReadXml(NomeFileXml) - DataSetXml.ReadXml(stream) - - '* Aggiunge il campo chiave - If NomeColonnaChiave <> "" Then - DataSetXml.Tables(NomeTabella).Constraints.Add(NomeColonnaChiave, DataSetXml.Tables(NomeTabella).Columns(NomeColonnaChiave), True) - End If - - '* Restituisce la risposta - Return DataSetXml - End Function - - Private Shared Function LeggiXmlDataSet(ByVal NomeTabella As String, ByVal NomeFileXml As String, Optional ByVal NomeColonnaChiave As String = "") As DataSet - '* Crea e Legge il dataset dal file xml - Dim DataSetXml As New System.Data.DataSet - DataSetXml.ReadXml(NomeFileXml) - - '* Aggiunge il campo chiave - If NomeColonnaChiave <> "" Then - DataSetXml.Tables(NomeTabella).Constraints.Add(NomeColonnaChiave, DataSetXml.Tables(NomeTabella).Columns(NomeColonnaChiave), True) - End If - - '* Restituisce la risposta - Return DataSetXml - End Function - - - Public Property NomeFileSetup() As String - Get - Return _NomeFileSetup - End Get - Set(ByVal Value As String) - _NomeFileSetup = Value - End Set - End Property - - -End Class diff --git a/imagecatalog/XYThreadPool.cs b/imagecatalog/XYThreadPool.cs deleted file mode 100644 index 9f675d1..0000000 --- a/imagecatalog/XYThreadPool.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System; -using System.Collections; -using System.Threading; - -namespace ImageCatalog -{ - public delegate void ThreadErrorHandlerDelegate(ThreadPoolWorkItem oWorkItem, Exception oError); - - public class ThreadPoolWorkItem - { - public bool m_bStoreOutput = false; - public string m_sName = ""; - public Delegate m_pMethod = null; - public object[] m_pInput = null; - public object m_oOutput = null; - public Exception m_oException = null; - - public ThreadPoolWorkItem() - { - } - - public ThreadPoolWorkItem(string sName, Delegate pMethod, object[] pInput, bool bStoreOutput) - { - m_sName = sName; - m_pMethod = pMethod; - m_pInput = pInput; - m_bStoreOutput = bStoreOutput; - } - } - - public class XYThreadPool - { - public XYThreadPool() - { - m_delegateThreadErrorHandler = new ThreadErrorHandlerDelegate(OnThreadError); - } - - private Hashtable m_htThreads = new Hashtable(256); - private int m_nMinThreadCount = 5; - private int m_nMaxThreadCount = 10; - private int m_nShutdownPause = 200; - private int m_nServerPause = 25; - private bool m_bContinue = false; - private Exception m_oException = null; - private Queue m_qInput = new Queue(1024); - private Queue m_qOutput = new Queue(1024); - private Delegate m_delegateThreadErrorHandler; - - private void ThreadProc() - { - while (m_bContinue) - { - object obj = null; - Monitor.Enter(this); - if (m_qInput.Count > 0) - obj = m_qInput.Dequeue(); - Monitor.Exit(this); - if (obj is null) - { - bool bQuit = false; - Monitor.Enter(this); - if (m_htThreads.Count > m_nMinThreadCount) - { - m_htThreads.Remove(Thread.CurrentThread.Name); - bQuit = true; - } - - Monitor.Exit(this); - if (bQuit) - return; - Thread.Sleep(10 * m_nServerPause); - } - else - { - ThreadPoolWorkItem oWorkItem = (ThreadPoolWorkItem)obj; - // oWorkItem.m_oOutput = oWorkItem.m_pMethod.DynamicInvoke(oWorkItem.m_pInput) - try - { - oWorkItem.m_oOutput = oWorkItem.m_pMethod.DynamicInvoke(oWorkItem.m_pInput); - } - catch (Exception oBug) - { - if (m_delegateThreadErrorHandler is object) - { - try - { - var pInput = new object[] { oWorkItem, oBug }; - m_delegateThreadErrorHandler.DynamicInvoke(pInput); - } - catch - { - } - } - } - - if (oWorkItem.m_bStoreOutput) - { - Monitor.Enter(m_qOutput); - m_qOutput.Enqueue(oWorkItem); - Monitor.Exit(m_qOutput); - } - - Thread.Sleep(m_nServerPause); - } - } - } - - private void OnThreadError(ThreadPoolWorkItem oWorkItem, Exception oError) - { - if (oWorkItem is null) - { - m_oException = oError; - } - else - { - oWorkItem.m_oException = oError; - } - } - - public void SetThreadErrorHandler(ThreadErrorHandlerDelegate pMethod) - { - Monitor.Enter(this); - m_delegateThreadErrorHandler = pMethod; - Monitor.Exit(this); - } - - public void SetServerPause(int nMilliseconds) - { - Monitor.Enter(this); - if (nMilliseconds > 9 & nMilliseconds < 101) - m_nServerPause = nMilliseconds; - Monitor.Exit(this); - } - - public void SetShutdownPause(int nMilliseconds) - { - Monitor.Enter(this); - m_nShutdownPause = nMilliseconds; - Monitor.Exit(this); - } - - public Exception GetException() - { - return m_oException; - } - - public void InsertWorkItem(ThreadPoolWorkItem oWorkItem) - { - try - { - Monitor.Enter(this); - m_qInput.Enqueue(oWorkItem); - if (m_bContinue && m_qInput.Count > m_htThreads.Count && m_htThreads.Count < m_nMaxThreadCount) - { - var th = new Thread(ThreadProc); - th.Name = Guid.NewGuid().ToString(); - m_htThreads.Add(th.Name, th); - th.Start(); - } - } - catch (Exception oBug) - { - m_oException = oBug; - } - finally - { - Monitor.Exit(this); - } - } - - public void InsertWorkItem(string sName, Delegate pMethod, object[] pArgs, bool bStoreOutput) - { - InsertWorkItem(new ThreadPoolWorkItem(sName, pMethod, pArgs, bStoreOutput)); - } - - public ThreadPoolWorkItem ExtractWorkItem() - { - object oWorkItem = null; - Monitor.Enter(m_qOutput); - if (m_qOutput.Count > 0) - oWorkItem = m_qOutput.Dequeue(); - Monitor.Exit(m_qOutput); - if (oWorkItem is null) - return null; - return (ThreadPoolWorkItem)oWorkItem; - } - - public bool StartThreadPool(int nMinThreadCount = 5, int nMaxThreadCount = 10) - { - try - { - Monitor.Enter(this); - if (m_bContinue == false) - { - m_bContinue = true; - if (nMinThreadCount > 0) - { - m_nMinThreadCount = nMinThreadCount; - } - - if (nMaxThreadCount > m_nMinThreadCount) - { - m_nMaxThreadCount = nMaxThreadCount; - } - else - { - m_nMaxThreadCount = 2 * m_nMinThreadCount; - } - - int i; - var loopTo = m_nMinThreadCount; - for (i = 1; i <= loopTo; i++) - { - var th = new Thread(ThreadProc); - th.Name = Guid.NewGuid().ToString(); - m_htThreads.Add(th.Name, th); - th.Start(); - } - } - - return true; - } - catch (Exception oBug) - { - m_bContinue = false; - m_oException = oBug; - return false; - } - finally - { - Monitor.Exit(this); - } - } - - public void StopThreadPool() - { - Monitor.Enter(this); - m_bContinue = false; - Thread.Sleep(Math.Max(200, m_nShutdownPause)); - if (m_nShutdownPause > 0) - { - var dict = m_htThreads.GetEnumerator(); - while (dict.MoveNext()) - { - Thread th = (Thread)dict.Value; - if (th.IsAlive) - { - try - { - th.Abort(); - } - catch - { - } - } - } - } - - m_htThreads.Clear(); - m_qInput.Clear(); - // m_qOutput.Clear() - Monitor.Exit(this); - } - - public int GetThreadCount() - { - Monitor.Enter(this); - int nCount = m_htThreads.Count; - Monitor.Exit(this); - return nCount; - } - } -} \ No newline at end of file diff --git a/imagecatalog/XYThreadPool.vb b/imagecatalog/XYThreadPool.vb deleted file mode 100644 index 63460d9..0000000 --- a/imagecatalog/XYThreadPool.vb +++ /dev/null @@ -1,185 +0,0 @@ -Option Explicit On -Option Strict Off - -Imports System.Threading -Imports System.Collections - -Public Delegate Sub ThreadErrorHandlerDelegate(ByVal oWorkItem As ThreadPoolWorkItem, ByVal oError As Exception) - -Public Class ThreadPoolWorkItem - Public m_bStoreOutput As Boolean = False - Public m_sName As String = "" - Public m_pMethod As [Delegate] = Nothing - Public m_pInput As Object() = Nothing - Public m_oOutput As Object = Nothing - Public m_oException As Exception = Nothing - Public Sub New() - End Sub - Public Sub New(ByVal sName As String, ByVal pMethod As [Delegate], ByVal pInput As Object(), ByVal bStoreOutput As Boolean) - m_sName = sName - m_pMethod = pMethod - m_pInput = pInput - m_bStoreOutput = bStoreOutput - End Sub -End Class - -Public Class XYThreadPool - Private m_htThreads As Hashtable = New Hashtable(256) - Private m_nMinThreadCount As Integer = 5 - Private m_nMaxThreadCount As Integer = 10 - Private m_nShutdownPause As Integer = 200 - Private m_nServerPause As Integer = 25 - Private m_bContinue As Boolean = False - Private m_oException As Exception = Nothing - Private m_qInput As Queue = New Queue(1024) - Private m_qOutput As Queue = New Queue(1024) - Private m_delegateThreadErrorHandler As [Delegate] = New ThreadErrorHandlerDelegate(AddressOf OnThreadError) - Private Sub ThreadProc() - While m_bContinue - Dim obj As Object = Nothing - Monitor.Enter(Me) - If m_qInput.Count > 0 Then obj = m_qInput.Dequeue() - Monitor.Exit(Me) - If obj Is Nothing Then - Dim bQuit As Boolean = False - Monitor.Enter(Me) - If m_htThreads.Count > m_nMinThreadCount Then - m_htThreads.Remove(Thread.CurrentThread.Name) - bQuit = True - End If - Monitor.Exit(Me) - If bQuit Then Return - Thread.Sleep(10 * m_nServerPause) - Else - Dim oWorkItem As ThreadPoolWorkItem = CType(obj, ThreadPoolWorkItem) - 'oWorkItem.m_oOutput = oWorkItem.m_pMethod.DynamicInvoke(oWorkItem.m_pInput) - Try - oWorkItem.m_oOutput = oWorkItem.m_pMethod.DynamicInvoke(oWorkItem.m_pInput) - Catch oBug As Exception - If Not m_delegateThreadErrorHandler Is Nothing Then - Try - Dim pInput As Object() = {oWorkItem, oBug} - m_delegateThreadErrorHandler.DynamicInvoke(pInput) - Catch - End Try - End If - End Try - If oWorkItem.m_bStoreOutput Then - Monitor.Enter(m_qOutput) - m_qOutput.Enqueue(oWorkItem) - Monitor.Exit(m_qOutput) - End If - Thread.Sleep(m_nServerPause) - End If - End While - End Sub - Private Sub OnThreadError(ByVal oWorkItem As ThreadPoolWorkItem, ByVal oError As Exception) - If oWorkItem Is Nothing Then - m_oException = oError - Else - oWorkItem.m_oException = oError - End If - End Sub - Public Sub SetThreadErrorHandler(ByVal pMethod As ThreadErrorHandlerDelegate) - Monitor.Enter(Me) - m_delegateThreadErrorHandler = pMethod - Monitor.Exit(Me) - End Sub - Public Sub SetServerPause(ByVal nMilliseconds As Integer) - Monitor.Enter(Me) - If nMilliseconds > 9 And nMilliseconds < 101 Then m_nServerPause = nMilliseconds - Monitor.Exit(Me) - End Sub - Public Sub SetShutdownPause(ByVal nMilliseconds As Integer) - Monitor.Enter(Me) - m_nShutdownPause = nMilliseconds - Monitor.Exit(Me) - End Sub - Public Function GetException() As Exception - Return m_oException - End Function - Public Sub InsertWorkItem(ByVal oWorkItem As ThreadPoolWorkItem) - Try - Monitor.Enter(Me) - m_qInput.Enqueue(oWorkItem) - If m_bContinue AndAlso m_qInput.Count > m_htThreads.Count AndAlso m_htThreads.Count < m_nMaxThreadCount Then - Dim th As Thread = New Thread(AddressOf ThreadProc) - th.Name = Guid.NewGuid.ToString() - m_htThreads.Add(th.Name, th) - th.Start() - End If - Catch oBug As Exception - m_oException = oBug - Finally - Monitor.Exit(Me) - End Try - End Sub - Public Sub InsertWorkItem(ByVal sName As String, ByVal pMethod As [Delegate], ByVal pArgs As Object(), ByVal bStoreOutput As Boolean) - InsertWorkItem(New ThreadPoolWorkItem(sName, pMethod, pArgs, bStoreOutput)) - End Sub - Public Function ExtractWorkItem() As ThreadPoolWorkItem - Dim oWorkItem As Object = Nothing - Monitor.Enter(m_qOutput) - If m_qOutput.Count > 0 Then oWorkItem = m_qOutput.Dequeue() - Monitor.Exit(m_qOutput) - If oWorkItem Is Nothing Then Return Nothing - Return CType(oWorkItem, ThreadPoolWorkItem) - End Function - Public Function StartThreadPool(Optional ByVal nMinThreadCount As Integer = 5, Optional ByVal nMaxThreadCount As Integer = 10) As Boolean - Try - Monitor.Enter(Me) - If m_bContinue = False Then - m_bContinue = True - If nMinThreadCount > 0 Then - m_nMinThreadCount = nMinThreadCount - End If - If nMaxThreadCount > m_nMinThreadCount Then - m_nMaxThreadCount = nMaxThreadCount - Else - m_nMaxThreadCount = 2 * m_nMinThreadCount - End If - Dim i As Integer - For i = 1 To m_nMinThreadCount - Dim th As Thread = New Thread(AddressOf ThreadProc) - th.Name = Guid.NewGuid.ToString() - m_htThreads.Add(th.Name, th) - th.Start() - Next i - End If - Return True - Catch oBug As Exception - m_bContinue = False - m_oException = oBug - Return False - Finally - Monitor.Exit(Me) - End Try - End Function - Public Sub StopThreadPool() - Monitor.Enter(Me) - m_bContinue = False - Thread.Sleep(Math.Max(200, m_nShutdownPause)) - If (m_nShutdownPause > 0) Then - Dim dict As IDictionaryEnumerator = m_htThreads.GetEnumerator() - While dict.MoveNext() - Dim th As Thread = CType(dict.Value(), Thread) - If th.IsAlive Then - Try - th.Abort() - Catch - End Try - End If - End While - End If - m_htThreads.Clear() - m_qInput.Clear() - ' m_qOutput.Clear() - Monitor.Exit(Me) - End Sub - Public Function GetThreadCount() As Integer - Monitor.Enter(Me) - Dim nCount As Integer = m_htThreads.Count - Monitor.Exit(Me) - Return nCount - End Function -End Class \ No newline at end of file