Csharp/C#教程:如何在我的WPF应用程序中保存图像分享


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

在我的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; } 

如何使用它

上述就是C#学习教程:如何在我的WPF应用程序中保存图像分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1015903.html

(0)
上一篇 2021年12月31日
下一篇 2021年12月31日

精彩推荐