From 4719f900ef0533dabfe4297952aae71c11de8cd4 Mon Sep 17 00:00:00 2001 From: Maddo Date: Tue, 4 Jul 2017 12:40:51 +0200 Subject: [PATCH] Scrittura testo base e rotazione autmatica --- CatalogLib/CatalogLib.csproj | 16 ++-- CatalogLib/ImageCreator.cs | 2 +- CatalogLib/ImageCreator2.cs | 2 +- CatalogLib/ImgSharpCreator.cs | 157 +++++++++++++++++++++------------- CatalogLib/PicSettings.cs | 2 +- CatalogLib/packages.config | 12 +-- WPFCatalog/WPFCatalog.csproj | 60 ------------- WPFCatalog/packages.config | 50 ----------- 8 files changed, 119 insertions(+), 182 deletions(-) diff --git a/CatalogLib/CatalogLib.csproj b/CatalogLib/CatalogLib.csproj index 66bed2d..8657ce6 100644 --- a/CatalogLib/CatalogLib.csproj +++ b/CatalogLib/CatalogLib.csproj @@ -54,10 +54,10 @@ - ..\packages\ImageSharp.1.0.0-alpha9-00140\lib\netstandard1.3\ImageSharp.dll + ..\packages\ImageSharp.1.0.0-alpha9-00169\lib\netstandard1.3\ImageSharp.dll - ..\packages\ImageSharp.Drawing.1.0.0-alpha9-00135\lib\netstandard1.1\ImageSharp.Drawing.dll + ..\packages\ImageSharp.Drawing.1.0.0-alpha9-00164\lib\netstandard1.1\ImageSharp.Drawing.dll ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll @@ -66,14 +66,17 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True + + ..\packages\SixLabors.Core.0.1.0-alpha0002\lib\netstandard1.1\SixLabors.Core.dll + - ..\packages\SixLabors.Fonts.0.1.0-alpha0011\lib\netstandard1.3\SixLabors.Fonts.dll + ..\packages\SixLabors.Fonts.0.1.0-alpha0014\lib\netstandard1.3\SixLabors.Fonts.dll - ..\packages\SixLabors.Shapes.0.1.0-alpha0017\lib\netstandard1.1\SixLabors.Shapes.dll + ..\packages\SixLabors.Shapes.0.1.0-alpha0018\lib\netstandard1.1\SixLabors.Shapes.dll - ..\packages\SixLabors.Shapes.Text.0.1.0-alpha0017\lib\netstandard1.1\SixLabors.Shapes.Text.dll + ..\packages\SixLabors.Shapes.Text.0.1.0-alpha0018\lib\netstandard1.1\SixLabors.Shapes.Text.dll @@ -142,6 +145,9 @@ ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll + + ..\packages\System.ValueTuple.4.4.0-preview1-25305-02\lib\netstandard1.0\System.ValueTuple.dll + diff --git a/CatalogLib/ImageCreator.cs b/CatalogLib/ImageCreator.cs index 82c6632..d338c95 100644 --- a/CatalogLib/ImageCreator.cs +++ b/CatalogLib/ImageCreator.cs @@ -167,7 +167,7 @@ namespace CatalogLib //FotoRuotaASinistra = false; _rotation = Rotazione.Normale; - if (_picSettings.UsaRotazioneAutomatica) + if (_picSettings.GeneraleRotazioneAutomatica) { // ci sono dati exif if (g.PropertyIdList.Length > 0) diff --git a/CatalogLib/ImageCreator2.cs b/CatalogLib/ImageCreator2.cs index 1bd4123..c10607d 100644 --- a/CatalogLib/ImageCreator2.cs +++ b/CatalogLib/ImageCreator2.cs @@ -104,7 +104,7 @@ namespace CatalogLib _rotation = Rotazione.Normale; - if (_picSettings.UsaRotazioneAutomatica) + if (_picSettings.GeneraleRotazioneAutomatica) { // ci sono dati exif if (_workingImage.PropertyIdList.Length > 0) diff --git a/CatalogLib/ImgSharpCreator.cs b/CatalogLib/ImgSharpCreator.cs index f74d9f2..1f5ac0d 100644 --- a/CatalogLib/ImgSharpCreator.cs +++ b/CatalogLib/ImgSharpCreator.cs @@ -8,7 +8,9 @@ using System.Numerics; using System.Text; using System.Threading.Tasks; using ImageSharp; +using ImageSharp.Drawing; using ImageSharp.PixelFormats; +using ImageSharp.Processing; using SixLabors.Fonts; using Font = SixLabors.Fonts.Font; using FontFamily = SixLabors.Fonts.FontFamily; @@ -29,56 +31,68 @@ namespace CatalogLib using (Image image = Image.Load(workFile.FullName)/* new Image(workFile.FullName)*/) { - if (PicSettings.Instance.UsaRotazioneAutomatica) + //image.Rotate(-90); + + if (PicSettings.Instance.GeneraleRotazioneAutomatica) { + image.AutoOrient(); + + //var exif = image.MetaData.ExifProfile; + //if (exif != null) + //{ + // var o = exif.GetValue(ExifTag.Orientation); + // if (o != null) + // { + // var v = (ushort)o.Value; - var exif = image.MetaData.ExifProfile; - if (exif != null) - { - var o = exif.GetValue(ExifTag.Orientation); - if (o != null) - { - int v = (int)o.Value; - switch (v) - { + + // switch (v) + // { - //1 = Horizontal(normal) - //2 = Mirror horizontal - //3 = Rotate 180 - //4 = Mirror vertical - //5 = Mirror horizontal and rotate 270 CW - //6 = Rotate 90 CW - //7 = Mirror horizontal and rotate 90 CW - //8 = Rotate 270 CW - case 1: - break; - case 2: - break; - case 3: - //image.Rotate(180f); + // //1 = Horizontal(normal) + // //2 = Mirror horizontal + // //3 = Rotate 180 + // //4 = Mirror vertical + // //5 = Mirror horizontal and rotate 270 CW + // //6 = Rotate 90 CW + // //7 = Mirror horizontal and rotate 90 CW + // //8 = Rotate 270 CW + // case 1: + // break; + // case 2: + // image.Flip(FlipType.Horizontal); + // break; + // case 3: + // //image.Rotate(180f); - //image.Rotate(90); - image.Rotate(180f); - break; - case 4: - break; - case 5: - break; - case 6: - image.Rotate(90); - break; - case 7: - break; - case 8: - image.Rotate(-90); - break; + // //image.Rotate(90); + // image.Rotate(RotateType.Rotate180); + // break; + // case 4: + // image.Flip(FlipType.Vertical); + // break; + // case 5: + // image.RotateFlip(RotateType.Rotate270, FlipType.Horizontal); + // break; + // case 6: + // image.Rotate(RotateType.Rotate90); + // break; + // case 7: + // image.RotateFlip(RotateType.Rotate90, FlipType.Horizontal); + // break; + // case 8: + // //image.Rotate(-90); + // image.Rotate(RotateType.Rotate270); + + // image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, new ExifValue(exif.GetValue(ExifTag.Orientation)).Value = (ushort)1); + // break; - } - } - } + // } + // } + //} } @@ -109,40 +123,65 @@ namespace CatalogLib Debug.WriteLine($"{_currentFile.Name} No text"); return; } - var fff = FontCollection.SystemFonts.Find(PicSettings.Instance.NomeFont); + + + var fo = SixLabors.Fonts.SystemFonts.Find(PicSettings.Instance.NomeFont); + + + //var fff = FontCollection.SystemFonts.Find(PicSettings.Instance.NomeFont); //var fff = FontCollection.SystemFonts.Find("Segoe Print"); - var font = new Font(fff, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular); + var font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular); //var font = new Font(fff, 8f, FontStyle.Regular); //Color c = Color.FromHex(FlipRgbString(PicSettings.Instance.ColoreTestoRGB)); Rgba32 g = Rgba32.FromHex(FlipRgbString(PicSettings.Instance.ColoreTestoRGB)); - TextMeasurer measurer = new TextMeasurer(); + //TextMeasurer measurer = new TextMeasurer(); - var size = measurer.MeasureText(PicSettings.Instance.TestoApplicareOrizzontale, font, 72); + //var size = measurer.MeasureText(PicSettings.Instance.TestoApplicareOrizzontale, font, 72); + //float scalingFactor = Math.Min(image.Width / size.Width, image.Height / size.Height); + //Font scaledFont = new Font(font, scalingFactor * font.Size); + + //image.DrawText(PicSettings.Instance.TestoApplicareOrizzontale, scaledFont, g, new Vector2(0, 0)); + + Vector2 center = new Vector2(image.Width / 2, image.Height / 2); //center horizontally, 10px down + + var size = TextMeasurer.Measure(PicSettings.Instance.TestoApplicareOrizzontale, new RendererOptions(font)); float scalingFactor = Math.Min(image.Width / size.Width, image.Height / size.Height); Font scaledFont = new Font(font, scalingFactor * font.Size); - image.DrawText("aaa", scaledFont, g, new Vector2(0, 0)); - //image.DrawText(PicSettings.Instance.TestoApplicareOrizzontale, font, Color.Black, ) - //image.DrawText(PicSettings.Instance.TestoApplicareOrizzontale, scaledFont, c, new Vector2(0, 0)); - //image.DrawText("sssssssssssssssssssssssssssssssssssssssssssssss", font, Color.Black, new Vector2(200, 200)); + image.DrawText(PicSettings.Instance.TestoApplicareOrizzontale, scaledFont, g, center, new TextGraphicsOptions(true) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom }); - //ahjsdfhjklasj - //double hr = image.MetaData.HorizontalResolution; - //double vr = image.MetaData.HorizontalResolution; - //image.MetaData.HorizontalResolution = 72; - //image.MetaData.VerticalResolution = 72; - //image.DrawText("sssssssssssssssssssssssssssssssssssssssssssssss", font, Color.Black, new Vector2(200, 200)); - //image.MetaData.HorizontalResolution = hr; - //image.MetaData.VerticalResolution = hr; + + } + + private void WriteTextFixed(Image image) + { + var fo = SixLabors.Fonts.SystemFonts.Find("Microsoft Sans Serif"); + var font = new Font(fo, 8, FontStyle.Regular); + Rgba32 g = Rgba32.FromHex("#FF00FFFF"); + Vector2 center = new Vector2(image.Width / 2, image.Height / 2); + var size = TextMeasurer.Measure("Test test test test test", new RendererOptions(font)); + float scalingFactor = Math.Min(image.Width / size.Width, image.Height / size.Height); + Font scaledFont = new Font(font, scalingFactor * font.Size); + image.DrawText("Test test test test test", scaledFont, g, center, new TextGraphicsOptions(true) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom }); } private string FlipRgbString(string originalString) { - string s = string.Concat("#", originalString.Substring(3, 6), originalString.Substring(1, 2)); + string s; + if (originalString.Length == 7) + { + s = string.Concat("#", originalString.Substring(1, 6)); + } + else + { + s = string.Concat("#", originalString.Substring(3, 6), originalString.Substring(1, 2)); + } + + return s; } } diff --git a/CatalogLib/PicSettings.cs b/CatalogLib/PicSettings.cs index 144d601..9453628 100644 --- a/CatalogLib/PicSettings.cs +++ b/CatalogLib/PicSettings.cs @@ -267,7 +267,7 @@ namespace CatalogLib get { return string.Empty; } } - public bool UsaRotazioneAutomatica { get; set; } + public DateTime DataPartenza { get; set; } public string TestoOrario { get; internal set; } public int DimStandard { get; internal set; } diff --git a/CatalogLib/packages.config b/CatalogLib/packages.config index f0e190c..8beea34 100644 --- a/CatalogLib/packages.config +++ b/CatalogLib/packages.config @@ -1,14 +1,15 @@  - - + + - - - + + + + @@ -56,6 +57,7 @@ + \ No newline at end of file diff --git a/WPFCatalog/WPFCatalog.csproj b/WPFCatalog/WPFCatalog.csproj index b3a3c60..f1c1b72 100644 --- a/WPFCatalog/WPFCatalog.csproj +++ b/WPFCatalog/WPFCatalog.csproj @@ -83,79 +83,22 @@ ..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll - - ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll - - - ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll - - - ..\packages\System.Buffers.4.3.0\lib\netstandard1.1\System.Buffers.dll - ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll True - - ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll - - - ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll - - - ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll - - - ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll - - - ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll - - - ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll - - - ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll - - - ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll - - - ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll - - - ..\packages\System.Numerics.Vectors.4.3.0\lib\net46\System.Numerics.Vectors.dll - - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.3.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll - - - ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - - - ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll - - - ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll - - - ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll - - - ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll - ..\packages\MahApps.Metro.1.5.0\lib\net45\System.Windows.Interactivity.dll @@ -168,9 +111,6 @@ 4.0 - - ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll - diff --git a/WPFCatalog/packages.config b/WPFCatalog/packages.config index 87aa9a9..189ae99 100644 --- a/WPFCatalog/packages.config +++ b/WPFCatalog/packages.config @@ -4,57 +4,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file