Catalog/CatalogLib/ImgSharpCreator.cs

117 lines
4.2 KiB
C#
Raw Normal View History

2017-02-28 09:59:17 +01:00
using System;
using System.Collections.Generic;
2017-03-23 14:36:06 +01:00
using System.Diagnostics;
using System.Drawing;
2017-02-28 09:59:17 +01:00
using System.IO;
using System.Linq;
2017-03-23 14:36:06 +01:00
using System.Numerics;
2017-02-28 09:59:17 +01:00
using System.Text;
using System.Threading.Tasks;
using ImageSharp;
2017-03-23 14:36:06 +01:00
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;
2017-03-16 21:30:37 +01:00
2017-02-28 09:59:17 +01:00
namespace CatalogLib
{
public class ImgSharpCreator : IImageProcessor
{
2017-03-23 14:36:06 +01:00
private FileInfo _currentFile;
2017-02-28 09:59:17 +01:00
public void Start(FileInfo workFile)
{
2017-03-23 14:36:06 +01:00
_currentFile = workFile;
2017-03-16 18:48:25 +01:00
using (Image image = new Image(workFile.FullName))
2017-02-28 09:59:17 +01:00
{
2017-03-16 18:48:25 +01:00
if (PicSettings.Instance.UsaRotazioneAutomatica)
{
var exif = image.MetaData.ExifProfile;
if (exif != null)
{
var o = exif.GetValue(ExifTag.Orientation);
if (o != null)
{
2017-03-17 16:23:29 +01:00
int v = (int)o.Value;
2017-03-16 18:48:25 +01:00
switch (v)
{
2017-03-17 16:23:29 +01:00
//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
2017-03-16 18:48:25 +01:00
case 1:
break;
case 2:
break;
case 3:
2017-03-16 21:30:37 +01:00
//image.Rotate(180f);
2017-03-17 16:23:29 +01:00
2017-03-16 21:30:37 +01:00
//image.Rotate(90);
image.Rotate(180f);
2017-03-16 18:48:25 +01:00
break;
case 4:
break;
case 5:
break;
case 6:
image.Rotate(90);
break;
case 7:
break;
case 8:
image.Rotate(-90);
break;
}
}
}
}
2017-03-23 14:36:06 +01:00
SetExtraText(image);
2017-03-16 18:48:25 +01:00
//JpegDecoder j = new JpegDecoder();
2017-03-23 14:36:06 +01:00
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));
2017-03-17 16:23:29 +01:00
image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name));
2017-03-16 18:48:25 +01:00
//image.Resize(200, 200).Save("");
2017-02-28 09:59:17 +01:00
}
}
2017-03-17 16:23:29 +01:00
2017-03-23 14:36:06 +01:00
private void SetExtraText(Image image)
2017-03-17 16:23:29 +01:00
{
2017-03-23 14:36:06 +01:00
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));
2017-03-17 16:23:29 +01:00
}
2017-02-28 09:59:17 +01:00
}
}