Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在我的WPF应用程序中保存图像_C#_Wpf - Fatal编程技术网

C# 如何在我的WPF应用程序中保存图像

C# 如何在我的WPF应用程序中保存图像,c#,wpf,C#,Wpf,在我的WPF应用程序中,我无法将应用程序中的图像保存在snap文件夹中。下面是我正在使用的代码 OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (ofd.ShowDialog() == DialogResult.OK) {

在我的WPF应用程序中,我无法将应用程序中的图像保存在snap文件夹中。下面是我正在使用的代码

OpenFileDialog ofd = new OpenFileDialog();
        ofd.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; 
        if (ofd.ShowDialog() == DialogResult.OK)
        {

            string filepath = ofd.FileName;
            File.Copy(ofd.FileName, Application.StartupPath + "\\snaps\\" + ofd.SafeFileName,true);
            photoTextBox.Text= ofd.SafeFileName;
            pictureBox1.Image = Image.FromFile(ofd.FileName);

        }

打开文件浏览器的代码

 string filepath;
        //browse Button
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Multiselect = false;    
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            bool? result = open.ShowDialog();

            if (result == true)
            {
                filepath = open.FileName; // Stores Original Path in Textbox    
                ImageSource imgsource = new BitmapImage(new Uri(filepath)); // Just show The File In Image when we browse It
                Clientimg.Source = imgsource;  
            }
        }
下面是用于保存文件的代码

private static String GetDestinationPath(string filename, string foldername)
        {
            String appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            appStartPath = String.Format(appStartPath + "\\{0}\\" + filename, foldername);
            return appStartPath;
        }
如何使用它

string name = System.IO.Path.GetFileName(filepath);
string destinationPath = GetDestinationPath(name,"YourFolderName");

File.Copy(filepath, destinationPath, true);

打开文件浏览器的代码

 string filepath;
        //browse Button
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Multiselect = false;    
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            bool? result = open.ShowDialog();

            if (result == true)
            {
                filepath = open.FileName; // Stores Original Path in Textbox    
                ImageSource imgsource = new BitmapImage(new Uri(filepath)); // Just show The File In Image when we browse It
                Clientimg.Source = imgsource;  
            }
        }
下面是用于保存文件的代码

private static String GetDestinationPath(string filename, string foldername)
        {
            String appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);

            appStartPath = String.Format(appStartPath + "\\{0}\\" + filename, foldername);
            return appStartPath;
        }
如何使用它

string name = System.IO.Path.GetFileName(filepath);
string destinationPath = GetDestinationPath(name,"YourFolderName");

File.Copy(filepath, destinationPath, true);

您想保存还是打开?我想将其保存在应用程序中的快照文件夹中,然后立即在图像控制中显示它您是否遇到异常?或者它只是无法加载到图像控件中?dutzu当我无法在应用程序中保存时,我无法编写类似于我的传统窗口应用程序的代码我无法理解为什么这些人将这个问题标记为错误,我问的是不是有什么问题?你想保存吗,或者你想打开?我想把它保存在我的应用程序中的快照文件夹中,然后立即在图像控制中显示它。你有例外吗?或者它只是无法加载到图像控件中?当我无法在应用程序中保存时,我无法编写类似于我的传统窗口应用程序的代码我无法理解为什么这些人将这个问题标记为错误,我问的是不是有什么问题??????