mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:46:30 +00:00
29 lines
833 B
C#
29 lines
833 B
C#
using System.IO;
|
|
using System.Windows.Media;
|
|
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;
|
|
}
|
|
|
|
public static Color CreateTransparent(this Color color, byte transparency) =>
|
|
Color.FromArgb(transparency, color.R, color.G, color.B);
|
|
} |