WPF image control source

后端 未结 3 1562
梦如初夏
梦如初夏 2021-01-17 23:53

im trying to recreate a very simple example of a C# project i WPF, its a simple image viewer.. from the sam\'s teach yourself C#, ive managed to get the open file dialog to

3条回答
  •  盖世英雄少女心
    2021-01-18 00:05

    you'll need to change the File Name into a URI and then create a bitmapimage

    :

    if (File.Exists(openfile.FileName))
    {
     // Create image element to set as icon on the menu element
     BitmapImage bmImage = new BitmapImage();
     bmImage.BeginInit();
     bmImage.UriSource = new Uri(openfile.FileName, UriKind.Absolute);
     bmImage.EndInit();
     // imagebox.Source = bmImage;
    }
    

提交回复
热议问题