public MainWindow()
{
InitializeComponent();
SetImage();
}
private void SetImage()
{
var streamResource = Application.GetResourceStream(LoadBitmapFromResource("/Resources/chromaKey_001.jpg"));
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = streamResource.Stream;
bitmapImage.EndInit();
img_box.Source = bitmapImage;
}
/// <summary>
/// Load a resource WPF-BitmapImage (png, bmp, ...) from embedded resource defined as 'Resource' not as 'Embedded resource'.
/// </summary>
/// <param name="pathInApplication">Path without starting slash</param>
/// <param name="assembly">Usually 'Assembly.GetExecutingAssembly()'. If not mentionned, I will use the calling assembly</param>
/// <returns></returns>
public static Uri LoadBitmapFromResource(string pathInApplication, Assembly assembly = null)
{
if (assembly == null)
{
assembly = Assembly.GetCallingAssembly();
}
if (pathInApplication[0] == '/')
{
pathInApplication = pathInApplication.Substring(1);
}
return new Uri(@"pack://application:,,,/" + assembly.GetName().Name + ";component/" + pathInApplication, UriKind.Absolute);
}
'C#' 카테고리의 다른 글
[C#] HttpClient download file example (2) | 2022.01.11 |
---|---|
[C#] .NET 6 HttpClient - The SSL connection could not be established, see inner exception (0) | 2021.12.14 |
[C#] OpenCV Cam ChromaKey - 캠 크로마키 (0) | 2021.12.02 |
[C# ] 요소수 중점 유통 주유소 재고현황 API 조회 (0) | 2021.11.20 |
[C#] 건강보험심사평가원_병원평가정보서비스 Rest Api 사용 (0) | 2021.11.13 |