windows 将图像从 Openfiledialog 保存到特定文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6579805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:17:48  来源:igfitidea点击:

Save Image to particular folder from Openfiledialog?

c#windows

提问by thinzar

I want to save images to my project folder from openfiledialog result . I don't get foler path to save . How do I get folder path ? How do I save that ? Please Help me.

我想将图像从 openfiledialog 结果保存到我的项目文件夹中。我没有找到保存路径。如何获取文件夹路径?我该如何保存?请帮我。

回答by RvdK

FileDialog.FileNamegives the full path to the file. And btw it is probably easier to use the SaveFileDialogbecause you want to save something, not open.

FileDialog.FileName提供文件的完整路径。顺便说一句,使用SaveFileDialog可能更容易,因为您想保存一些东西,而不是打开。

回答by Carmelo La Monica

Hello thinzar,

你好,

      private void button2_Click(object sender, EventArgs e)
      {
        Bitmap myBitmap = new Bitmap();
        this.saveFileDialog1.FileName = Application.ExecutablePath;
        if (this.saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            myBitmap.Save(this.saveFileDialog1.FileName);
        }
      }

Bye

再见

回答by Iain Ward

The System.Windows.Forms.FolderBrowserDialogallows the user to select a folder. Maybe that would be a better option?

System.Windows.Forms.FolderBrowserDialog允许用户选择一个文件夹。也许那会是一个更好的选择?

回答by Ian

Something alone these lines

单独的东西这些线

Bitmap myImage = new Bitmap();

// draw on the image

SaveFileDialog sfd = new SaveFileDialog ();
if(sfd.ShowDialog() == DialogResult.OK)
{
   myImage.Save(sfd.FileName);
}

回答by GeoffM

I guess you're opening a file elsewhere and then using the results to later save stuff into the directory you opened from?

我猜你是在别处打开一个文件,然后使用结果将内容保存到你打开的目录中?

DialogResult result = OpenFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
  string directoryName = Path.GetDirectoryName(OpenFileDialog1.FileName);
  // directoryName now contains the path
}