我正在使用 WPF 4.0。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.IO;
namespace ResourcesLearning
{
class Program
{
[STAThread]
static void Main()
{
Application app = new Application();
Window win = new Window();
Image img = new Image();
String fileName = @"C:\Users\dev\Pictures\1.png";
//It work fine (I see image)
BitmapImage bim = new BitmapImage(new Uri(fileName));
//It not work (I do not see image)
//BitmapImage bim = new BitmapImage();
//bim.UriSource = new Uri(fileName);
//It not work (I do not see image)
//FileStream fs = new FileStream(fileName, FileMode.Open);
//BitmapImage bim = new BitmapImage();
//bim.StreamSource = fs;
img.Source = bim;
win.Content = img;
app.Run(win);
}
}
}
为什么我的评论变体没有显示图像?只有第一个变体成功。