62,046
社区成员
发帖
与我相关
我的任务
分享
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;
}