码迷,mamicode.com
首页 > Windows程序 > 详细

wpf 获取image控件的图片并保存

时间:2017-11-15 22:13:17      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:mode   记忆   mod   c#   image   name   restore   save   dialog   

XMAL代码如下:

<Image Name="ImageToSave" Source="Images/pic_bg.png" Grid.RowSpan="3" Grid.ColumnSpan="3"  ></Image>

C#代码如下:

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Image Files (*.bmp, *.png, *.jpg)|*.bmp;*.png;*.jpg | All Files | *.*";
sfd.RestoreDirectory = true;//保存对话框是否记忆上次打开的目录
if (sfd.ShowDialog() == true)
{
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)this.ImageToSave.Source));
using (FileStream stream = new FileStream(sfd.FileName, FileMode.Create))
encoder.Save(stream);
}

wpf 获取image控件的图片并保存

标签:mode   记忆   mod   c#   image   name   restore   save   dialog   

原文地址:http://www.cnblogs.com/dotnetHui/p/7840644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!