Scrittura testo base e rotazione autmatica
This commit is contained in:
parent
da6b7abf8b
commit
4719f900ef
8 changed files with 126 additions and 189 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue