如何将图像保存到特定目录 [英] how to save an image to a specific directory

查看:104
本文介绍了如何将图像保存到特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,其中有一个图像控件,当我点击它时,会显示一个OpenFileDialog,以便从文件中选择一个图像!现在我想将此图像保存到名为working_folder的特定文件夹中



这是我要将图像保存到的文件夹的位置:

 System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()。Location)+   \\working_folder \\; 



和图像的位置是这个D:\ Users \\ \\ mowglin \图片\ Images,图片类型为.tif

请参阅下面的代码,以便更清楚:

  bool  imgLoaded =  false ; 

图片currentImg =(图片)发件人;
if (currentImg.Tag!= null
imgLoaded =( BOOL )currentImg.Tag;
if (!imgLoaded)
{
string filename = < span class =code-string> ;
OpenFileDialog dlg = new OpenFileDialog();
dlg.DefaultExt = 。tif;
dlg.Filter = (* .tif,*。tiff)| * .tif; * .tiff ;
bool result =( bool )dlg.ShowDialog();
if (result == true
{
filename = dlg.FileName;
currentImg.Source = new BitmapImage( new Uri(filename));
this .UpdateLayout();
currentImg.Tag = true ;
}
}



所以我的问题是,如何将图像保存到specefic目录?

解决方案

尝试currentImg.Save(路径,[你要保存的格式]);



http://msdn.microsoft.com/en-us/library/9t4syfhh(v=vs.110).aspx [ ^ ]

I have a WPF application where there is an image control and when I click on it, an OpenFileDialog displays in order to choose an image from a file! now I want to save this image to a specific folder called working_folder

this is the location of the folder I want to save the image to:

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "\\working_folder\\";


and the location of the image is this D:\Users\mowglin\Pictures\Images, and the image is type ".tif"
Please see the code below to make this more clear:

bool imgLoaded = false;

            Image currentImg = (Image)sender;
            if (currentImg.Tag != null)
            imgLoaded = (bool)currentImg.Tag;
            if (!imgLoaded)
            {
                string filename = "";
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.DefaultExt = ".tif";
                dlg.Filter = "(*.tif,*.tiff)|*.tif;*.tiff";
                bool result = (bool)dlg.ShowDialog(this);
                if (result == true)
                {
                    filename = dlg.FileName;
                    currentImg.Source = new BitmapImage(new Uri(filename));
                    this.UpdateLayout();
                    currentImg.Tag = true;
                }
            }


so my question is, how can I save the image to a specefic directory?

解决方案

Try currentImg.Save(path,[what format you want to save]);

http://msdn.microsoft.com/en-us/library/9t4syfhh(v=vs.110).aspx[^]


这篇关于如何将图像保存到特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆