如何加载图像到图片框

本文关键字:图像 何加载 加载 | 更新日期: 2023-09-27 18:08:06

我在c#编程,我已经有了它,我可以选择我的文件从我的手机与这个文本:

private void Button_Click_2(object sender, RoutedEventArgs e)
{
    var FileOpenPicker = new Windows.Storage.Pickers.FileOpenPicker();
    FileOpenPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
    FileOpenPicker.FileTypeFilter.Add(".jpg");
    FileOpenPicker.FileTypeFilter.Add(".jpeg");
    FileOpenPicker.FileTypeFilter.Add(".png");
    FileOpenPicker.PickSingleFileAndContinue();

如何让图片在图片框中弹出?

如何加载图像到图片框

使用FileDialog并从选定的路径加载位图:

   using (OpenFileDialog dlg = new OpenFileDialog())
{
    dlg.Title = "Open Image";
    dlg.Filter = "bmp files (*.bmp)|*.bmp";
    if (dlg.ShowDialog() == DialogResult.OK)
    {
        // Create a new Bitmap object from the picture file on disk,
        // and assign that to the PictureBox.Image property
        PictureBox1.Image = new Bitmap(dlg.FileName);
    }
}