方法封装:
调用方法:
其中资源文件为 AppResource。
当给image的Source(ImageSource)赋值的用法:
参考网址:
http://wenku.baidu.com/link?url=c4ep6KIE0w3unKpzaQtf-bHcWhdu14X9h4DvOFH_wya5VIgsQF8-AZiT6zZTZ9niUxRmMtrn9iXvm8qsZGzkpSFsf8y_D84nBvxFZtkzHby
- public static System.Windows.Media.ImageBrush GetImageBrushFrom_PResource(System.Drawing.Bitmap imgSrc)
- {
- System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imgSrc);
- MemoryStream stream = new MemoryStream();
-
- bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
- System.Windows.Media.ImageBrush imgBrush = new System.Windows.Media.ImageBrush();
- System.Windows.Media.ImageSourceConverter isConverter = new System.Windows.Media.ImageSourceConverter();
- imgBrush.ImageSource = (System.Windows.Media.ImageSource)isConverter.ConvertFrom(stream);
-
- return imgBrush;
- }
其中资源文件为 AppResource。
- this.button6.Background = GetImageBrushFrom_PResource(AppResource.cScrnPointerChecked);
- this.image1.Source = Utility.GetImageBrushFrom_PResource(AppResource.MPNews).ImageSource;
参考网址:
http://wenku.baidu.com/link?url=c4ep6KIE0w3unKpzaQtf-bHcWhdu14X9h4DvOFH_wya5VIgsQF8-AZiT6zZTZ9niUxRmMtrn9iXvm8qsZGzkpSFsf8y_D84nBvxFZtkzHby