【问题标题】:c# get Image directory path after selecting image on open file dialogc#在打开文件对话框中选择图像后获取图像目录路径
【发布时间】:2020-03-27 03:21:40
【问题描述】:

有没有办法在文件对话框中选择后获取图像目录路径

示例C:\Users\Admin\Desktop\IMG\pix200.jpg

我有一个代码可以在选择图像并在 PictureBox 中显示图像之后打开文件对话框 如前所述,我需要获取图像位置或路径目录

private void student_Edit_PictureBox_Front_DoubleClick(object sender, EventArgs e)
    {
        OpenFileDialog openFD = new OpenFileDialog();
        openFD.Filter = "Bitmaps|*.bmp|jpeg|*.jpg";

        if (openFD.ShowDialog() == DialogResult.OK)
        {
            student_Picture_Edit.Image = Bitmap.FromFile(openFD.FileName);
            student_Edit_PictureBox_Front.Image = Bitmap.FromFile(openFD.FileName);

            //I want to get the directory path Picturebox.Imagelocation is not working for me
        }
    }

有解决办法吗?

【问题讨论】:

标签: c#


【解决方案1】:

尝试使用Path.GetDirectoryName 方法。 示例:

string path = Path.GetDirectoryName(openFD.FileName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多