I want to make a WPF app to show some images on my hard drive. Here's my attempt :
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Drawing;
namespace Photo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Image myimage = Image.FromFile(@"C:\images\myimage.jpg");
}
}
}
Here is the error I get :
'System.Windows.Controls.Image' does not contain a definition for 'FromFile'
How can I get rid of this error? Thanks..
Image.FromFile
is available with System.Drawing.Image
. It is not available with System.Windows.Controls.Image
. For WPF you shouldn't be using System.Drawing.Image
.
So the question is how to load Image
object in WPF from a file. Use:
System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
myImage.Source = new BitmapImage(new Uri(@"C:\images\myimage.jpg"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With