上传图片:
OpenFileDialog //表示一个通用对话框,用户可以使用此对话框来指定一个或多个要打开的文件的文件名。
Multiselect //获取或设置一个选项,该选项指示 Microsoft.Win32.OpenFileDialog 是否允许用户选择多个文件。
Filter // 获取或设置筛选器字符串,该字符串确定在 Microsoft.Win32.OpenFileDialog 或 Microsoft.Win32.SaveFileDialog
// 中显示的文件类型。
ShowDialog // 显示通用对话框。
OpenFile // 为用户使用 Microsoft.Win32.OpenFileDialog 选定的文件打开只读流。
Read // 当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。
Add // 将对象添加到 System.Collections.Generic.List`1 的结尾处。
如果图片需要保存,使用 List<byte[]> 来装图片
List<byte[]> lstBytes = new List<byte[]>();
//浏览图片
private void btn_Open_Click(object sender, RoutedEventArgs e)
{
lstBytes.Clear();
Stream photo = null;
int length;
Microsoft.Win32.OpenFileDialog ofWenJian = new Microsoft.Win32.OpenFileDialog();
ofWenJian.Multiselect = true;
ofWenJian.Filter = "ALL Image Files|*.*";
if ((bool)ofWenJian.ShowDialog())
{
if ((photo = ofWenJian.OpenFile()) != null)
{
length = (int)photo.Length;
byte[] bytes = new byte[length];
photo.Read(bytes, 0, length);
lstBytes.Add(bytes);
BitmapImage images = new BitmapImage(new Uri(ofWenJian.FileName));
img_photo.Source = images;
txt_Load.Text = ofWenJian.FileName;
}
}
else
{
MessageBox.Show("未选择");
}
}