方法封装:
-
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);
当给image的Source(ImageSource)赋值的用法:
-
this.image1.Source = Utility.GetImageBrushFrom_PResource(AppResource.MPNews).ImageSource;
参考网址:
阅读(2469) | 评论(0) | 转发(0) |