Cancellazione Task
This commit is contained in:
parent
9fd336befb
commit
d2ab7bfce6
5 changed files with 188 additions and 46 deletions
|
|
@ -23,7 +23,16 @@ namespace CatalogLib
|
|||
{
|
||||
public class ImgSharpCreator : IImageProcessor
|
||||
{
|
||||
private Image<Rgba32> _logo;
|
||||
public ImgSharpCreator()
|
||||
{
|
||||
if (!PicSettings.Instance.EnableLogo) return;
|
||||
if (string.IsNullOrWhiteSpace(PicSettings.Instance.LogoPath)) return;
|
||||
if (!File.Exists(PicSettings.Instance.LogoPath)) return;
|
||||
|
||||
_logo = Image.Load(PicSettings.Instance.LogoPath);
|
||||
|
||||
}
|
||||
private FileInfo _currentFile;
|
||||
public void Start(FileInfo workFile)
|
||||
{
|
||||
|
|
@ -141,7 +150,7 @@ namespace CatalogLib
|
|||
//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), new JpegEncoder(){Quality = PicSettings.Instance.CompressioneJpeg});
|
||||
image.Save(Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name), new JpegEncoder() { Quality = PicSettings.Instance.CompressioneJpeg });
|
||||
//image.Resize(200, 200).Save("");
|
||||
|
||||
MaddoLogger.Log("Saved Image: {0} to: {1}", workFile.FullName, Path.Combine(PicSettings.Instance.DirectoryDestinazione, workFile.Name));
|
||||
|
|
@ -201,7 +210,7 @@ namespace CatalogLib
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
// todo calcolare ridimensionamento
|
||||
var size = new Vector2();
|
||||
var size = new Size();
|
||||
if (PicSettings.Instance.FotoMantieniDimensioni)
|
||||
{
|
||||
|
||||
|
|
@ -213,15 +222,15 @@ namespace CatalogLib
|
|||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
break;
|
||||
|
|
@ -229,24 +238,24 @@ namespace CatalogLib
|
|||
if (image.Width > image.Height)
|
||||
{
|
||||
// larghezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
size = GetResizeDimensions(new Size(image.Width, image.Height),
|
||||
new Size(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
|
||||
|
||||
}
|
||||
image.Mutate(x => x.Resize((int)Math.Round(size.X), (int)Math.Round(size.Y), resampler));
|
||||
image.Mutate(x => x.Resize((size.Width), (size.Height), resampler));
|
||||
|
||||
//Width Formula:
|
||||
//original height / original width * new width = new height
|
||||
|
|
@ -261,15 +270,15 @@ namespace CatalogLib
|
|||
|
||||
}
|
||||
|
||||
private Vector2 GetResizeDimensions(Vector2 originalSize, Vector2 newSize, bool isWidth)
|
||||
private Size GetResizeDimensions(Size originalSize, Size newSize, bool isWidth)
|
||||
{
|
||||
if (isWidth)
|
||||
{
|
||||
return new Vector2(newSize.X, originalSize.Y / originalSize.X * newSize.X);
|
||||
return new Size(newSize.Width, originalSize.Height / originalSize.Width * newSize.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector2(originalSize.X / originalSize.Y * newSize.Y, newSize.Y);
|
||||
return new Size(originalSize.Width / originalSize.Height * newSize.Height, newSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -464,6 +473,49 @@ namespace CatalogLib
|
|||
|
||||
}
|
||||
|
||||
private void AddLogo(Image<Rgba32> image)
|
||||
{
|
||||
//if (string.IsNullOrWhiteSpace(PicSettings.Instance.LogoPath)) return;
|
||||
//if (!File.Exists(PicSettings.Instance.LogoPath)) return;
|
||||
//using (Image<Rgba32> logo = Image.Load(PicSettings.Instance.LogoPath))
|
||||
//{
|
||||
// Size size = new Size();
|
||||
// Point location = new Point();
|
||||
// image.Mutate(x => x.DrawImage(logo, size, location, new GraphicsOptions()
|
||||
// {
|
||||
|
||||
// }));
|
||||
|
||||
//}
|
||||
|
||||
if (_logo != null)
|
||||
{
|
||||
var width = PicSettings.Instance.LogoWidth;
|
||||
var height = PicSettings.Instance.LogoHeight;
|
||||
var fattoreAlt = _logo.Height / height;
|
||||
var fattoreLarg = _logo.Width / width;
|
||||
var nuovaSize = new Size();
|
||||
|
||||
nuovaSize = GetResizeDimensions(new Size(_logo.Width, _logo.Height), new Size(width, height), fattoreLarg > fattoreAlt);
|
||||
//todo riguardare perché non torna cosa ho fatto
|
||||
|
||||
int margineUsato;
|
||||
int margineL;
|
||||
bool inPercentualeL;
|
||||
|
||||
inPercentualeL = PicSettings.Instance.LogoMargin.EndsWith("%");
|
||||
if (inPercentualeL)
|
||||
{ margineL = int.Parse(PicSettings.Instance.LogoMargin.Replace("%", ""));}
|
||||
else
|
||||
{
|
||||
margineL = int.Parse(PicSettings.Instance.LogoMargin);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void WriteTextFixed(Image<Rgba32> image)
|
||||
{
|
||||
var fo = SixLabors.Fonts.SystemFonts.Find("Microsoft Sans Serif");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue