Scrittura testo base e rotazione autmatica
This commit is contained in:
parent
da6b7abf8b
commit
4719f900ef
8 changed files with 126 additions and 189 deletions
|
|
@ -54,10 +54,10 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ImageSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ImageSharp.1.0.0-alpha9-00140\lib\netstandard1.3\ImageSharp.dll</HintPath>
|
||||
<HintPath>..\packages\ImageSharp.1.0.0-alpha9-00169\lib\netstandard1.3\ImageSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageSharp.Drawing, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ImageSharp.Drawing.1.0.0-alpha9-00135\lib\netstandard1.1\ImageSharp.Drawing.dll</HintPath>
|
||||
<HintPath>..\packages\ImageSharp.Drawing.1.0.0-alpha9-00164\lib\netstandard1.1\ImageSharp.Drawing.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
|
||||
|
|
@ -66,14 +66,17 @@
|
|||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Core, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.Core.0.1.0-alpha0002\lib\netstandard1.1\SixLabors.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Fonts, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.Fonts.0.1.0-alpha0011\lib\netstandard1.3\SixLabors.Fonts.dll</HintPath>
|
||||
<HintPath>..\packages\SixLabors.Fonts.0.1.0-alpha0014\lib\netstandard1.3\SixLabors.Fonts.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Shapes, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.Shapes.0.1.0-alpha0017\lib\netstandard1.1\SixLabors.Shapes.dll</HintPath>
|
||||
<HintPath>..\packages\SixLabors.Shapes.0.1.0-alpha0018\lib\netstandard1.1\SixLabors.Shapes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SixLabors.Shapes.Text, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SixLabors.Shapes.Text.0.1.0-alpha0017\lib\netstandard1.1\SixLabors.Shapes.Text.dll</HintPath>
|
||||
<HintPath>..\packages\SixLabors.Shapes.Text.0.1.0-alpha0018\lib\netstandard1.1\SixLabors.Shapes.Text.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
|
|
@ -142,6 +145,9 @@
|
|||
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.4.0-preview1-25305-02\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ namespace CatalogLib
|
|||
|
||||
_rotation = Rotazione.Normale;
|
||||
|
||||
if (_picSettings.UsaRotazioneAutomatica)
|
||||
if (_picSettings.GeneraleRotazioneAutomatica)
|
||||
{
|
||||
// ci sono dati exif
|
||||
if (_workingImage.PropertyIdList.Length > 0)
|
||||
|
|
|
|||
|
|
@ -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<Rgba32> 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<Rgba32> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ImageSharp" version="1.0.0-alpha9-00140" targetFramework="net46" />
|
||||
<package id="ImageSharp.Drawing" version="1.0.0-alpha9-00135" targetFramework="net46" />
|
||||
<package id="ImageSharp" version="1.0.0-alpha9-00169" targetFramework="net46" />
|
||||
<package id="ImageSharp.Drawing" version="1.0.0-alpha9-00164" targetFramework="net46" />
|
||||
<package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net46" />
|
||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net46" />
|
||||
<package id="NETStandard.Library" version="1.6.1" targetFramework="net46" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
|
||||
<package id="SixLabors.Fonts" version="0.1.0-alpha0011" targetFramework="net46" />
|
||||
<package id="SixLabors.Shapes" version="0.1.0-alpha0017" targetFramework="net46" />
|
||||
<package id="SixLabors.Shapes.Text" version="0.1.0-alpha0017" targetFramework="net46" />
|
||||
<package id="SixLabors.Core" version="0.1.0-alpha0002" targetFramework="net46" />
|
||||
<package id="SixLabors.Fonts" version="0.1.0-alpha0014" targetFramework="net46" />
|
||||
<package id="SixLabors.Shapes" version="0.1.0-alpha0018" targetFramework="net46" />
|
||||
<package id="SixLabors.Shapes.Text" version="0.1.0-alpha0018" targetFramework="net46" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Buffers" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net46" />
|
||||
|
|
@ -56,6 +57,7 @@
|
|||
<package id="System.Threading.Tasks" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Threading.Tasks.Parallel" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.ValueTuple" version="4.4.0-preview1-25305-02" targetFramework="net46" />
|
||||
<package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net46" />
|
||||
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net46" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue