Ridimensionamento e opzioni
This commit is contained in:
parent
a81451bd6b
commit
9fd336befb
7 changed files with 212 additions and 18 deletions
|
|
@ -32,7 +32,6 @@ Global
|
|||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x64.Build.0 = Debug|x64
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Debug|x86.Build.0 = Debug|x86
|
||||
{8D3AA2B0-8F06-4A61-9CAD-B920EB1A8E9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
|
|||
|
|
@ -12,4 +12,29 @@
|
|||
Centro,
|
||||
Destra
|
||||
}
|
||||
|
||||
public enum ResizeModes
|
||||
{
|
||||
Bicubic,
|
||||
Box,
|
||||
CatmullRom,
|
||||
Hermite,
|
||||
Lanczos2,
|
||||
Lanczos3,
|
||||
Lanczos5,
|
||||
Lanczos8,
|
||||
MitchellNetravali,
|
||||
NearestNeighbor,
|
||||
Robidoux,
|
||||
Spline,
|
||||
Triangle,
|
||||
Welch
|
||||
|
||||
}
|
||||
|
||||
public enum ResizeDimensions
|
||||
{
|
||||
LatoLungo,
|
||||
LatoCorto
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ using MaddoLibrary.Base.Log;
|
|||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing;
|
||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SixLabors.Primitives;
|
||||
|
|
@ -52,11 +53,10 @@ namespace CatalogLib
|
|||
|
||||
if (PicSettings.Instance.FotoRidimensiona)
|
||||
{
|
||||
// todo calcolare ridimensionamento
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, new BicubicResampler()));
|
||||
Resize(image);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (PicSettings.Instance.GeneraleRotazioneAutomatica)
|
||||
{
|
||||
image.Mutate(img => img.AutoOrient());
|
||||
|
|
@ -125,8 +125,8 @@ namespace CatalogLib
|
|||
if (PicSettings.Instance.EnableText)
|
||||
{
|
||||
//SetTextTest(image);
|
||||
SetExtraText(image, isRotated);
|
||||
|
||||
SetExtraText(image, isRotated);
|
||||
|
||||
|
||||
MaddoLogger.Log("Drawn text on Image: {0}", workFile.FullName);
|
||||
}
|
||||
|
|
@ -141,7 +141,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));
|
||||
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));
|
||||
|
|
@ -150,6 +150,129 @@ namespace CatalogLib
|
|||
MaddoLogger.Log("Time Taken for {0}: {1}", workFile.FullName, s.Elapsed);
|
||||
}
|
||||
|
||||
private void Resize(Image<Rgba32> image)
|
||||
{
|
||||
IResampler resampler;
|
||||
switch (PicSettings.Instance.ResizeMode)
|
||||
{
|
||||
case ResizeModes.Bicubic:
|
||||
resampler = new BicubicResampler();
|
||||
break;
|
||||
case ResizeModes.Box:
|
||||
resampler = new BoxResampler();
|
||||
break;
|
||||
case ResizeModes.CatmullRom:
|
||||
resampler = new CatmullRomResampler();
|
||||
break;
|
||||
case ResizeModes.Hermite:
|
||||
resampler = new HermiteResampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos2:
|
||||
resampler = new Lanczos2Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos3:
|
||||
resampler = new Lanczos3Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos5:
|
||||
resampler = new Lanczos5Resampler();
|
||||
break;
|
||||
case ResizeModes.Lanczos8:
|
||||
resampler = new Lanczos8Resampler();
|
||||
break;
|
||||
case ResizeModes.MitchellNetravali:
|
||||
resampler = new MitchellNetravaliResampler();
|
||||
break;
|
||||
case ResizeModes.NearestNeighbor:
|
||||
resampler = new NearestNeighborResampler();
|
||||
break;
|
||||
case ResizeModes.Robidoux:
|
||||
resampler = new RobidouxResampler();
|
||||
break;
|
||||
case ResizeModes.Spline:
|
||||
resampler = new SplineResampler();
|
||||
break;
|
||||
case ResizeModes.Triangle:
|
||||
resampler = new TriangleResampler();
|
||||
break;
|
||||
case ResizeModes.Welch:
|
||||
resampler = new WelchResampler();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
// todo calcolare ridimensionamento
|
||||
var size = new Vector2();
|
||||
if (PicSettings.Instance.FotoMantieniDimensioni)
|
||||
{
|
||||
|
||||
|
||||
|
||||
switch (PicSettings.Instance.ResizeDimension)
|
||||
{
|
||||
case ResizeDimensions.LatoLungo:
|
||||
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),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(PicSettings.Instance.FotoLarghezza, PicSettings.Instance.FotoAltezza),
|
||||
false);
|
||||
}
|
||||
break;
|
||||
case ResizeDimensions.LatoCorto:
|
||||
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),
|
||||
false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// altezza è il lato lungo
|
||||
size = GetResizeDimensions(new Vector2(image.Width, image.Height),
|
||||
new Vector2(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));
|
||||
|
||||
//Width Formula:
|
||||
//original height / original width * new width = new height
|
||||
//Height Formula:
|
||||
//orignal width / orignal height * new height = new width
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
image.Mutate(x => x.Resize(PicSettings.Instance.FotoAltezza, PicSettings.Instance.FotoLarghezza, resampler));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Vector2 GetResizeDimensions(Vector2 originalSize, Vector2 newSize, bool isWidth)
|
||||
{
|
||||
if (isWidth)
|
||||
{
|
||||
return new Vector2(newSize.X, originalSize.Y / originalSize.X * newSize.X);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Vector2(originalSize.X / originalSize.Y * newSize.Y, newSize.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetTextTest(Image<Rgba32> image)
|
||||
{
|
||||
string text = "test test test test test testtest test test test test test test";
|
||||
|
|
@ -204,9 +327,9 @@ namespace CatalogLib
|
|||
font = new Font(fo, (float)PicSettings.Instance.DimensioneFont, FontStyle.Bold);
|
||||
}
|
||||
// todo corsivo
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//var font = new Font(fff, 8f, FontStyle.Regular);
|
||||
|
||||
|
||||
|
|
@ -227,7 +350,7 @@ namespace CatalogLib
|
|||
var size = TextMeasurer.Measure(text, new RendererOptions(font));
|
||||
|
||||
var larghezzaStandard = size.Width;
|
||||
var dimensioneStandard = (int) Math.Round(PicSettings.Instance.DimensioneFont);
|
||||
var dimensioneStandard = (int)Math.Round(PicSettings.Instance.DimensioneFont);
|
||||
if (size.Width > image.Width)
|
||||
{
|
||||
var c = dimensioneStandard;
|
||||
|
|
@ -254,7 +377,7 @@ namespace CatalogLib
|
|||
new RendererOptions(font));
|
||||
if (size.Width < image.Width)
|
||||
{
|
||||
larghezzaStandard = (int) Math.Round(size.Width);
|
||||
larghezzaStandard = (int)Math.Round(size.Width);
|
||||
break;
|
||||
}
|
||||
if (c <= 5)
|
||||
|
|
@ -277,7 +400,7 @@ namespace CatalogLib
|
|||
}
|
||||
|
||||
float xCenterofImg = 0;
|
||||
|
||||
|
||||
// stringformat
|
||||
|
||||
switch (PicSettings.Instance.TextAlignment)
|
||||
|
|
@ -313,7 +436,7 @@ namespace CatalogLib
|
|||
font = new Font(fo, dimensioneStandard, FontStyle.Regular);
|
||||
}
|
||||
|
||||
image.Mutate(x => x.DrawText(text, font, gBack, new PointF((float)Math.Round(xCenterofImg + 1) , (float)Math.Round(yPosFromBottom + 1)), new TextGraphicsOptions()
|
||||
image.Mutate(x => x.DrawText(text, font, gBack, new PointF((float)Math.Round(xCenterofImg + 1), (float)Math.Round(yPosFromBottom + 1)), new TextGraphicsOptions()
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -480,6 +480,19 @@ namespace CatalogLib
|
|||
get => GetBool("Threading", true);
|
||||
set => SetBool("Threading", value);
|
||||
}
|
||||
|
||||
public ResizeModes ResizeMode
|
||||
{
|
||||
get => GetEnum("ResizeMode", ResizeModes.Bicubic);
|
||||
set => SetString("ResizeMode", value.ToString());
|
||||
}
|
||||
|
||||
public ResizeDimensions ResizeDimension
|
||||
{
|
||||
get => GetEnum("ResizeDimension", CatalogLib.ResizeDimensions.LatoCorto);
|
||||
set => SetString("ResizeDimension", value.ToString());
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public string Posizione
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,16 @@
|
|||
d:DataContext="{d:DesignInstance wpfCatalog:MainWindowViewModel}"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
|
||||
<ObjectDataProvider x:Key="ResizeEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="catalogLib:ResizeModes" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
<ObjectDataProvider x:Key="ResizeDimensionsEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="catalogLib:ResizeDimensions" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<ScrollViewer>
|
||||
|
|
@ -126,6 +135,7 @@
|
|||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="15*"/>
|
||||
|
|
@ -156,12 +166,18 @@
|
|||
|
||||
|
||||
<CheckBox Grid.Row="4" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,16,0,17.88" IsChecked="{Binding FotoMantieniDimensioni}"/>
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Grid.ColumnSpan="2" HorizontalAlignment="Left" Text="Mantieni Dimensioni Originali" TextWrapping="WrapWithOverflow" Margin="4,0,4,25.88" />
|
||||
<TextBlock Grid.Row="4" Grid.Column="0" VerticalAlignment="Center" Grid.ColumnSpan="2" HorizontalAlignment="Left" Text="Mantieni Rapporto di aspetto" TextWrapping="WrapWithOverflow" Margin="4,0,4,25.88" />
|
||||
|
||||
<Label Grid.Row="5" Grid.Column="0" Content="Suffisso" Grid.ColumnSpan="2" Margin="0,0.12,0,-0.12" />
|
||||
<TextBox Grid.Row="5" Grid.Column="2" Margin="4,4.12,4,3.88" Text="{Binding FotoSuffisso}" />
|
||||
|
||||
|
||||
<Label Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2">Algoritmo di ridimensionamento</Label>
|
||||
<ComboBox Grid.Row="6" Grid.Column="2" ItemsSource="{Binding Source={StaticResource ResizeEnum}}" SelectedItem="{Binding ResizeMode}"></ComboBox>
|
||||
|
||||
<Label Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2">Lato ridimensionamento</Label>
|
||||
<ComboBox Grid.Row="7" Grid.Column="2" ItemsSource="{Binding Source={StaticResource ResizeDimensionsEnum}}" SelectedItem="{Binding ResizeDimension}"></ComboBox>
|
||||
|
||||
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
Text="{Binding FontName}"
|
||||
></TextBox>
|
||||
<Label Content="Grassetto" Grid.Row="2" Grid.Column="0"></Label>
|
||||
<CheckBox Grid.Row="2" Grid.Column="1"></CheckBox>
|
||||
<CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{Binding Grassetto}"></CheckBox>
|
||||
|
||||
<Label Content="Corsivo" Grid.Row="3" Grid.Column="0"></Label>
|
||||
<CheckBox Grid.Row="3" Grid.Column="1"></CheckBox>
|
||||
|
|
|
|||
|
|
@ -823,6 +823,24 @@ namespace WPFCatalog
|
|||
set { PicSettings.TextAlignment = value; RaisePropertyChanged("TextAlignment"); }
|
||||
}
|
||||
|
||||
public ResizeModes ResizeMode
|
||||
{
|
||||
get => PicSettings.ResizeMode;
|
||||
set { PicSettings.ResizeMode = value; RaisePropertyChanged("ResizeMode"); }
|
||||
}
|
||||
|
||||
public ResizeDimensions ResizeDimension
|
||||
{
|
||||
get => PicSettings.ResizeDimension;
|
||||
set { PicSettings.ResizeDimension = value; RaisePropertyChanged("ResizeDimension"); }
|
||||
}
|
||||
|
||||
public bool Grassetto
|
||||
{
|
||||
get => PicSettings.Grassetto;
|
||||
set { PicSettings.Grassetto = value; RaisePropertyChanged("Grassetto"); }
|
||||
}
|
||||
|
||||
//public PicSettings.Positions Positions
|
||||
//{
|
||||
// get => PicSettings.Positions;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue