【C#】コンソールアプリからWPF起動して画像を表示する
前回の記事でフォームで画像表示するのがアレな気がしたのでWPFでやりました。
参照にPresentationFrameworkとPresentationCoreとWindowsBaseを追加します。
MainメソッドにSTAThread属性を追加します。
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; class Program { [STAThread] static void Main(string[] args) { var img = new Image() { Source = new BitmapImage( new Uri(@"C:\Users\xxxxx\Desktop\sample.png")) }; var window = new Window() { Title = "サンプル", Width = 300, Height = 300, Content = new Grid { Children = { new StackPanel { Children= {img,} } } } }; var app = new Application(); app.Run(window); Console.ReadLine(); } }