mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
31 lines
847 B
C#
31 lines
847 B
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Media.Imaging;
|
|
using Avalonia.Platform;
|
|
using System;
|
|
|
|
namespace Mesen.Utilities
|
|
{
|
|
public static class ImageUtilities
|
|
{
|
|
public static Image FromAsset(string source)
|
|
{
|
|
IAssetLoader? assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>();
|
|
if(assetLoader != null) {
|
|
return new Image() { Source = new Bitmap(assetLoader.Open(new Uri("avares://Mesen/" + source))) };
|
|
} else {
|
|
throw new Exception("AssetLoader unavailable");
|
|
}
|
|
}
|
|
|
|
public static Bitmap BitmapFromAsset(string source)
|
|
{
|
|
IAssetLoader? assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>();
|
|
if(assetLoader != null) {
|
|
return new Bitmap(assetLoader.Open(new Uri("avares://Mesen/" + source)));
|
|
} else {
|
|
throw new Exception("AssetLoader unavailable");
|
|
}
|
|
}
|
|
}
|
|
}
|