日期:2014-05-17 浏览次数:20468 次
private void FindPic_Click(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "PNG File(*.png)|*.png"; ; dialog.Multiselect = false; if (dialog.ShowDialog() == true) { FileStream fs = new FileStream(dialog.FileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); this._imageBinary = br.ReadBytes((int)fs.Length); this._imgLocalPath = dialog.FileName; br.Close(); fs.Close(); this.IMG.Source = ByteArrayToBitmapImage(this._imageBinary); } } BitmapImage ByteArrayToBitmapImage(byte[] byteArray) { BitmapImage bmp = null; try { bmp = new BitmapImage(); bmp.BeginInit(); bmp.StreamSource = new MemoryStream(byteArray); bmp.EndInit(); } catch { bmp = null; } return bmp; }