'System.Windows.Controls.Image' does not contain a definition for 'FromFile'
-
Hello, I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application. How can I get rid of this error? Thanks. Code :
using System.Drawing;
namespace Photo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();string filename1 = @"C:\\images\\mainicon.jpg"; Image image1 = Image.FromFile(filename1); } }
}
Error : 'System.Windows.Controls.Image' does not contain a definition for 'FromFile'
-
Hello, I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application. How can I get rid of this error? Thanks. Code :
using System.Drawing;
namespace Photo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();string filename1 = @"C:\\images\\mainicon.jpg"; Image image1 = Image.FromFile(filename1); } }
}
Error : 'System.Windows.Controls.Image' does not contain a definition for 'FromFile'
At a guess, do you have a control on your window with the name set to "Image"? Try creating an alias for the
Image
type name, or using the fully qualified type name:using DrawingImage = System.Drawing.Image;
...
DrawingImage image1 = DrawingImage.FromFile(filename1);// -or-
var image1 = System.Drawing.Image.FromFile(filename1);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Hello, I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application. How can I get rid of this error? Thanks. Code :
using System.Drawing;
namespace Photo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();string filename1 = @"C:\\images\\mainicon.jpg"; Image image1 = Image.FromFile(filename1); } }
}
Error : 'System.Windows.Controls.Image' does not contain a definition for 'FromFile'
Your codes contains
using System.Drawing
but you are getting error from System.Windows.Controls namespace. Most likely there is either some namespace confusion for compiler. Try specify the namespace explicitly in the last line:
Image image1 = System.Drawing.Image.FromFile(filename1);
-- "My software never has bugs. It just develops random features."
-
Your codes contains
using System.Drawing
but you are getting error from System.Windows.Controls namespace. Most likely there is either some namespace confusion for compiler. Try specify the namespace explicitly in the last line:
Image image1 = System.Drawing.Image.FromFile(filename1);
-- "My software never has bugs. It just develops random features."
Thank you for your reply, I did what you said and I get this : The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) Thanks.
-
Thank you for your reply, I did what you said and I get this : The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) Thanks.
-
Hello, I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application. How can I get rid of this error? Thanks. Code :
using System.Drawing;
namespace Photo
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();string filename1 = @"C:\\images\\mainicon.jpg"; Image image1 = Image.FromFile(filename1); } }
}
Error : 'System.Windows.Controls.Image' does not contain a definition for 'FromFile'