积极答复者
搞了两天的Image了!在线等啊!!!

问题
-
希望按下button后 出现打开文件窗口
选中一张图片后出现一张图片
结果我代码能取到图片路径 就是不能显示图片!
求助啊!搞这个东西我都要哭了!
windo1.xaml文件
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xml:lang="en-US"
xmlns="http://schemas.microsoft.com/expression/interactivedesigner/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="MySoftWare.Window1"
x:Name="Window"
Title="MySoftware"
WindowState="Maximized" Canvas.Top="Auto">
<Canvas>
<Button Name="Open" Click="Open_Click">Open</Button>
<Image Name="image" Canvas.Left="100" Canvas.Top="100"></Image>
</Canvas>
</Window>
windows1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
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;
namespace MySoftWare
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Open_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dialogOpenFile = new Microsoft.Win32.OpenFileDialog();
dialogOpenFile.ShowDialog();
if (dialogOpenFile.FileName != null)
{
Image pic = new Image();
Uri uri = new Uri(dialogOpenFile.FileName, UriKind.Absolute);
ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
pic.SetValue(Image.SourceProperty, img);
}
}
}
}
求可以跑并显示图片的代码!
答案
-
你好,
这个论坛主要是讨论Silverlight技术的.关于WPF的问题你可以在下面的论坛提问.
http://social.msdn.microsoft.com/forums/en-US/wpf/threads/
谢谢
全部回复
-
Code Snippet
private void Button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if ((bool)openFileDialog1.ShowDialog())
{
System.IO.Stream stream = openFileDialog1.File.OpenRead();
System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage();
bi.SetSource(stream);
img.Source = bi;
stream.Close();
}
} -
你好,
这个论坛主要是讨论Silverlight技术的.关于WPF的问题你可以在下面的论坛提问.
http://social.msdn.microsoft.com/forums/en-US/wpf/threads/
谢谢