将BitMapImage保存到应用程序文件夹

时间:2013-06-05 09:16:20

标签: c# winforms bitmapimage

我正在尝试在应用程序文件夹路径中保存BitmapImage。我正在使用以下代码

OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
var resultSaveDialog = fileDialog.ShowDialog();
if (fileDialog.FileName != "" && resultSaveDialog == System.Windows.Forms.DialogResult.OK)
{
    fileDialog.OpenFile();
    strPath = fileDialog.FileName;
    System.Windows.Media.Imaging.BitmapImage myBitmapImage = new System.Windows.Media.Imaging.BitmapImage();
    myBitmapImage.BeginInit();
    myBitmapImage.DecodePixelHeight = 20;
    myBitmapImage.DecodePixelWidth = 20;
    myBitmapImage.UriSource = new Uri(strPath, UriKind.Absolute);
    myBitmapImage.EndInit();                                      
    System.Windows.Media.ImageSource imgSource = myBitmapImage;     
 }           

我想将此myBitmapImage保存到应用程序文件夹LA_Img。我怎么能这样做..我无法找到任何方法..

1 个答案:

答案 0 :(得分:0)

您可以使用BitmapEncoder。有关JpegBitmapEncoderPngBitmapEncoder等派生类的信息,请参见System.Windows.Media.Imaging-Namespace