shoko/Media/MagickMediaHandler.cs

32 lines
748 B
C#

using Raylib_cs;
using ImageMagick;
namespace Shoko;
[MediaType("image/*")]
class MagickMediaHandler : ImageMediaHandler
{
public MagickMediaHandler(ProtoHandler content)
{
Content = content;
}
public override async Task Load()
{
Title = Content.URL.AbsolutePath;
using(var magic = new MagickImage())
{
await magic.ReadAsync(Content.Content);
magic.Format = MagickFormat.Png;
var image = Raylib.LoadImageFromMemory(".png", magic.ToByteArray());
Texture = Raylib.LoadTextureFromImage(image);
Raylib.UnloadImage(image);
}
OnLoaded();
}
~MagickMediaHandler()
{
Raylib.UnloadTexture(Texture);
}
}