学海无涯

导航

选择图片并加载显示

  private void shopPicButton_Click(object sender, RoutedEventArgs e)
        {//选择图片并加载显示
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "JPEG Files(*.jpg) | *.jpg | PNG Files(*.png) | *.png | BMP Files(*.bmp) | *.bmp | All files(*.*) | *.*";
            openFileDialog.Title = "选择一个图片文件";
            if (openFileDialog.ShowDialog()==true)
            {
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.UriSource = new Uri(openFileDialog.FileName);
                //bitmapImage.DecodePixelWidth = 200;
                bitmapImage.EndInit();
                myImage.Source = bitmapImage;
            }
        }

        private void clearPicButton_Click(object sender, RoutedEventArgs e)
        {//清除图片
            myImage.Source = null;
        }

  

posted on 2022-12-25 15:11  宁静致远.  阅读(13)  评论(0编辑  收藏  举报