给Image.Source赋值

wpf中不能直接给路径真的很郁闷!

using System.Windows.Interop;

using System.Drawing;

将System.Drawing.Image对象作为图源:

wpfImg1.Source = Imaging.CreateBitmapSourceFromHBitmap(((Bitmap)Image01).GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

将资源中的图形作为图源:

wpfImg2.Source = Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.background.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); 

posted @ 2011-09-22 08:53  Mark_ybh  阅读(711)  评论(0编辑  收藏  举报