WPF设置资源文件到background案例

方法封装:
  1. public static System.Windows.Media.ImageBrush GetImageBrushFrom_PResource(System.Drawing.Bitmap imgSrc)
  2.         {
  3.             System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imgSrc);
  4.             MemoryStream stream = new MemoryStream();

  5.             bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
  6.             System.Windows.Media.ImageBrush imgBrush = new System.Windows.Media.ImageBrush();
  7.             System.Windows.Media.ImageSourceConverter isConverter = new System.Windows.Media.ImageSourceConverter();
  8.             imgBrush.ImageSource = (System.Windows.Media.ImageSource)isConverter.ConvertFrom(stream);

  9.             return imgBrush;
  10.         }
调用方法:
其中资源文件为AppResource。
  1. this.button6.Background = GetImageBrushFrom_PResource(AppResource.cScrnPointerChecked);
当给image的Source(ImageSource)赋值的用法:
  1. this.image1.Source = Utility.GetImageBrushFrom_PResource(AppResource.MPNews).ImageSource;

参考网址:
http://wenku.baidu.com/link?url=c4ep6KIE0w3unKpzaQtf-bHcWhdu14X9h4DvOFH_wya5VIgsQF8-AZiT6zZTZ9niUxRmMtrn9iXvm8qsZGzkpSFsf8y_D84nBvxFZtkzHby
上一篇:从华为IT运维,我终于知道了为什么华为敢做云


下一篇:“应用程序无法正常启动(oxc000007b)”解决方案