潜移默化学会WPF--绘图 学习(一)
指定图片资源
<Image x:Name="IconImage" Source="Res/0.png" Stretch="Fill"/>
后台
private int _iconindex = 1;
public int IconIndex
{
get { return _iconindex; }
set
{
_iconindex = value;
var uri = new Uri("/AppleMenu;component/Res/" + value + ".png", UriKind.Relative);
IconImage.Source = new System.Windows.Media.Imaging.BitmapImage(uri);
}
}
只看红色那一段
/程序集名称;component/具体目录/图片名称,UriKind.Relative
现在教你怎样教image上的图片另存为
//imgShow为Image控件
BitmapSource bsrc = (BitmapSource)ImgShow.Source; System.Windows.Forms.SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog(); sf.DefaultExt = ".png"; sf.Filter = "png (.png)|*.png"; if (System.Windows.Forms.DialogResult.OK == sf.ShowDialog()) { PngBitmapEncoder pngE = new PngBitmapEncoder(); pngE.Frames.Add(BitmapFrame.Create(bsrc)); using (Stream stream = File.Create(sf.FileName)) { pngE.Save(stream); } }