mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Profiles - Resize profile images to 128x128
This commit is contained in:
parent
e9f2b77fd6
commit
56abc48ab3
40
src/Artemis.UI/Extensions/Bitmap.cs
Normal file
40
src/Artemis.UI/Extensions/Bitmap.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System.IO;
|
||||||
|
using Avalonia.Media.Imaging;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Extensions;
|
||||||
|
|
||||||
|
public class BitmapExtensions
|
||||||
|
{
|
||||||
|
public static Bitmap LoadAndResize(string file, int size)
|
||||||
|
{
|
||||||
|
using SKBitmap source = SKBitmap.Decode(file);
|
||||||
|
return Resize(source, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Bitmap LoadAndResize(Stream stream, int size)
|
||||||
|
{
|
||||||
|
using SKBitmap source = SKBitmap.Decode(stream);
|
||||||
|
return Resize(source, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Bitmap Resize(SKBitmap source, int size)
|
||||||
|
{
|
||||||
|
int newWidth, newHeight;
|
||||||
|
float aspectRatio = (float) source.Width / source.Height;
|
||||||
|
|
||||||
|
if (aspectRatio > 1)
|
||||||
|
{
|
||||||
|
newWidth = size;
|
||||||
|
newHeight = (int) (size / aspectRatio);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newWidth = (int) (size * aspectRatio);
|
||||||
|
newHeight = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
using SKBitmap resizedBitmap = source.Resize(new SKImageInfo(newWidth, newHeight), SKFilterQuality.High);
|
||||||
|
return new Bitmap(resizedBitmap.Encode(SKEncodedImageFormat.Png, 100).AsStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ using Artemis.Core;
|
|||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.DryIoc.Factories;
|
using Artemis.UI.DryIoc.Factories;
|
||||||
|
using Artemis.UI.Extensions;
|
||||||
using Artemis.UI.Screens.VisualScripting;
|
using Artemis.UI.Screens.VisualScripting;
|
||||||
using Artemis.UI.Shared;
|
using Artemis.UI.Shared;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
@ -231,7 +232,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
|||||||
else if (_selectedIconPath != null)
|
else if (_selectedIconPath != null)
|
||||||
{
|
{
|
||||||
await using FileStream fileStream = File.OpenRead(_selectedIconPath);
|
await using FileStream fileStream = File.OpenRead(_selectedIconPath);
|
||||||
ProfileConfiguration.Icon.SetIconByStream(Path.GetFileName(_selectedIconPath), fileStream);
|
ProfileConfiguration.Icon.SetIconByStream(fileStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +245,7 @@ public class ProfileConfigurationEditViewModel : DialogViewModelBase<ProfileConf
|
|||||||
if (result == null)
|
if (result == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SelectedBitmapSource = new Bitmap(result[0]);
|
SelectedBitmapSource = BitmapExtensions.LoadAndResize(result[0], 128);
|
||||||
_selectedIconPath = result[0];
|
_selectedIconPath = result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user