mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-24 23:47:11 +02:00
Use SkiaSharp for Avalonia in place of ImageSharp (#6269)
* Rebased Transformation all at once Use SkiaSharp instead of ImageSharp * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Change back unintentionally changed comment --------- Co-authored-by: Ac_K <Acoustik666@gmail.com> Co-authored-by: Emmanuel Hansen <emmausssss@gmail.com>
This commit is contained in:
parent
07435ad844
commit
595e514f18
7 changed files with 104 additions and 71 deletions
|
@ -6,12 +6,8 @@ using Ryujinx.Ava.UI.Controls;
|
|||
using Ryujinx.Ava.UI.Models;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Png;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SkiaSharp;
|
||||
using System.IO;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Views.User
|
||||
{
|
||||
|
@ -70,15 +66,25 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
{
|
||||
if (ViewModel.SelectedImage != null)
|
||||
{
|
||||
MemoryStream streamJpg = new();
|
||||
Image avatarImage = Image.Load(ViewModel.SelectedImage, new PngDecoder());
|
||||
using var streamJpg = new MemoryStream();
|
||||
using var bitmap = SKBitmap.Decode(ViewModel.SelectedImage);
|
||||
using var newBitmap = new SKBitmap(bitmap.Width, bitmap.Height);
|
||||
|
||||
avatarImage.Mutate(x => x.BackgroundColor(new Rgba32(
|
||||
ViewModel.BackgroundColor.R,
|
||||
ViewModel.BackgroundColor.G,
|
||||
ViewModel.BackgroundColor.B,
|
||||
ViewModel.BackgroundColor.A)));
|
||||
avatarImage.SaveAsJpeg(streamJpg);
|
||||
using (var canvas = new SKCanvas(newBitmap))
|
||||
{
|
||||
canvas.Clear(new SKColor(
|
||||
ViewModel.BackgroundColor.R,
|
||||
ViewModel.BackgroundColor.G,
|
||||
ViewModel.BackgroundColor.B,
|
||||
ViewModel.BackgroundColor.A));
|
||||
canvas.DrawBitmap(bitmap, 0, 0);
|
||||
}
|
||||
|
||||
using (var image = SKImage.FromBitmap(newBitmap))
|
||||
using (var dataJpeg = image.Encode(SKEncodedImageFormat.Jpeg, 100))
|
||||
{
|
||||
dataJpeg.SaveTo(streamJpg);
|
||||
}
|
||||
|
||||
_profile.Image = streamJpg.ToArray();
|
||||
|
||||
|
|
|
@ -9,11 +9,9 @@ using Ryujinx.Ava.UI.Controls;
|
|||
using Ryujinx.Ava.UI.Models;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.HLE.FileSystem;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SkiaSharp;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Views.User
|
||||
{
|
||||
|
@ -102,13 +100,19 @@ namespace Ryujinx.Ava.UI.Views.User
|
|||
|
||||
private static byte[] ProcessProfileImage(byte[] buffer)
|
||||
{
|
||||
using Image image = Image.Load(buffer);
|
||||
using var bitmap = SKBitmap.Decode(buffer);
|
||||
|
||||
image.Mutate(x => x.Resize(256, 256));
|
||||
var resizedBitmap = bitmap.Resize(new SKImageInfo(256, 256), SKFilterQuality.High);
|
||||
|
||||
using MemoryStream streamJpg = new();
|
||||
using var streamJpg = new MemoryStream();
|
||||
|
||||
image.SaveAsJpeg(streamJpg);
|
||||
if (resizedBitmap != null)
|
||||
{
|
||||
using var image = SKImage.FromBitmap(resizedBitmap);
|
||||
using var dataJpeg = image.Encode(SKEncodedImageFormat.Jpeg, 100);
|
||||
|
||||
dataJpeg.SaveTo(streamJpg);
|
||||
}
|
||||
|
||||
return streamJpg.ToArray();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue