C# 如何复制在OpenDialog中选择的图像
我创建了一个C#Windows窗体应用程序,其中包括一个按钮。单击此按钮时,将打开一个OpenFile对话框,通过该对话框可以选择图像文件。我希望此图像复制到另一个文件夹,并具有相同的名称。特别是我的Visual Studio项目的调试文件夹中名为“Images”的文件夹。此外,我需要从新位置将此图像副本显示在GUI上的pictureBox中。这就是我到目前为止所做的工作C# 如何复制在OpenDialog中选择的图像,c#,image,C#,Image,我创建了一个C#Windows窗体应用程序,其中包括一个按钮。单击此按钮时,将打开一个OpenFile对话框,通过该对话框可以选择图像文件。我希望此图像复制到另一个文件夹,并具有相同的名称。特别是我的Visual Studio项目的调试文件夹中名为“Images”的文件夹。此外,我需要从新位置将此图像副本显示在GUI上的pictureBox中。这就是我到目前为止所做的工作 private void createNewButton_Click(object sender, EventArgs e)
private void createNewButton_Click(object sender, EventArgs e)
{
Image tempImage;
string destinationDirectory = @"C:\Users\Username\Desktop\ImageEditorProject\bin\Debug\Images";
imageDisplayerPictureBox.Controls.Clear();
OpenFileDialog fileOpener = new OpenFileDialog();
fileOpener.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png|All Files (*.*)|*.*";
if (fileOpener.ShowDialog() == DialogResult.OK)
{
filePath = fileOpener.FileName;
//Image must be duplicated to Images folder
imageDisplayerPictureBox.Image = Bitmap.FromFile(destinationDirectory);
}
提前感谢您的帮助:)尝试使用此功能
File.Copy();