Use ImageMagick to support even more image formats

This commit is contained in:
Yuki 2023-10-02 19:17:30 -04:00
parent cf8e42587b
commit fcca47458f
3 changed files with 36 additions and 2 deletions

View File

@ -16,8 +16,12 @@ class ImageMediaHandler : MediaHandler
["image/qoi"] = ".qoi",
["image/x-qoi"] = ".qoi",
};
Texture2D Texture;
float Zoom = 1;
protected Texture2D Texture;
protected float Zoom = 1;
public ImageMediaHandler()
{
}
public ImageMediaHandler(ProtoHandler content)
{
Content = content;

View File

@ -0,0 +1,29 @@
using Raylib_cs;
using ImageMagick;
namespace Shoko;
[MediaType("image/*")]
class MagickMediaHandler : ImageMediaHandler
{
public MagickMediaHandler(ProtoHandler content)
{
Content = content;
}
public override void Load()
{
using(var magic = new MagickImage(Content.Content))
{
magic.Format = MagickFormat.Png;
var image = Raylib.LoadImageFromMemory(".png", magic.ToByteArray());
Texture = Raylib.LoadTextureFromImage(image);
Raylib.UnloadImage(image);
}
}
~MagickMediaHandler()
{
Raylib.UnloadTexture(Texture);
}
}

View File

@ -18,6 +18,7 @@
<PackageReference Include="Raylib-cs" Version="4.5.0.4" />
<PackageReference Include="rlImgui-cs" Version="1.0.3" />
<PackageReference Include="ImGui.NET" Version="1.89.9.2" />
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.3.0" />
</ItemGroup>
</Project>