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