This commit is contained in:
Daniel Clark
2021-02-05 01:39:51 +00:00
parent 666067a36c
commit 45a9eb9cd2
73 changed files with 2669 additions and 0 deletions
@@ -0,0 +1,31 @@
using Microsoft.Windows.Sdk;
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media;
namespace NotificationFlyout.Wpf.UI.Extensions
{
public static class ImageSourceExtensions
{
public static Icon ConvertToIcon(this ImageSource imageSource, uint dpi)
{
if (imageSource == null) return null;
var uri = new Uri(imageSource.ToString(), UriKind.RelativeOrAbsolute);
var streamResource = Application.GetResourceStream(uri);
if (streamResource == null) throw new ArgumentException(nameof(streamResource));
return new Icon(streamResource.Stream, new System.Drawing.Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
}
private enum SystemMetricFlag : int
{
SM_CXICON = 11,
SM_CYICON = 12,
SM_CXSMICON = 49,
SM_CYSMICON = 50
}
}
}