mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:16:30 +00:00
25 lines
657 B
C#
25 lines
657 B
C#
using System.IO;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace Azaion.Common.Extensions;
|
|
|
|
public static class BitmapExtensions
|
|
{
|
|
public static async Task<BitmapImage> OpenImage(this string imagePath)
|
|
{
|
|
await using var stream = File.OpenRead(imagePath);
|
|
return OpenImage(stream);
|
|
}
|
|
|
|
public static BitmapImage OpenImage(this Stream stream)
|
|
{
|
|
stream.Seek(0, SeekOrigin.Begin);
|
|
var image = new BitmapImage();
|
|
image.BeginInit();
|
|
image.CacheOption = BitmapCacheOption.OnLoad;
|
|
image.StreamSource = stream;
|
|
image.EndInit();
|
|
image.Freeze();
|
|
return image;
|
|
}
|
|
} |