簡體   English   中英

'System.Windows.Controls.Image'不包含'FromFile'的定義

[英]'System.Windows.Controls.Image' does not contain a definition for 'FromFile'

我想制作一個WPF應用程序,以便在我的硬盤上顯示一些圖像。 這是我的嘗試:

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");
        }
    }
}

這是我得到的錯誤:

'System.Windows.Controls.Image'不包含'FromFile'的定義

我怎樣才能擺脫這個錯誤? 謝謝..

Image.FromFileSystem.Drawing.Image 它不適用於System.Windows.Controls.Image 對於WPF,您不應該使用System.Drawing.Image

所以問題是如何從文件中加載WPF中的Image對象。 使用:

System.Windows.Controls.Image myImage = new System.Windows.Controls.Image();
myImage.Source = new BitmapImage(new Uri(@"C:\images\myimage.jpg"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM