using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; using ImageSharp; using SixLabors.Fonts; using Color = ImageSharp.Color; using Font = SixLabors.Fonts.Font; using FontFamily = SixLabors.Fonts.FontFamily; using FontStyle = SixLabors.Fonts.FontStyle; using Image = ImageSharp.Image; namespace CatalogLib { public class ImgSharpCreator : IImageProcessor { private FileInfo _currentFile; public void Start(FileInfo workFile) { _currentFile = workFile; using (Image image = new Image(workFile.FullName)) { if (PicSettings.Instance.UsaRotazioneAutomatica) { var exif = image.MetaData.ExifProfile; if (exif != null) { var o = exif.GetValue(ExifTag.Orientation); if (o != null) { int v = (int)o.Value; 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); //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; } } } } SetExtraText(image); //JpegDecoder j = new JpegDecoder(); var va = Vector.IsHardwareAccelerated; image.Resize(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza); //image.Resize(2240, 2240); //var fff = FontCollection.SystemFonts.Find(PicSettings.Instance.NomeFont); //var font = new Font(fff, (float)PicSettings.Instance.DimensioneFont, FontStyle.Regular); //image.DrawText("sssssssssssssssssssssssssssssssssssssssssssssss", font, Color.Black, new Vector2(200, 200)); image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name)); //image.Resize(200, 200).Save(""); } } private void SetExtraText(Image image) { if (string.IsNullOrWhiteSpace(PicSettings.Instance.TestoApplicareOrizzontale)) { Debug.WriteLine($"{_currentFile.Name} No text"); return; } 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(fff, 8f, FontStyle.Regular); image.DrawText(PicSettings.Instance.TestoApplicareOrizzontale, font, Color.Black, new Vector2(200, 200)); //image.DrawText("sssssssssssssssssssssssssssssssssssssssssssssss", font, Color.Black, new Vector2(200, 200)); } } }