wpf如何将图片设置为窗体的背景

时间:2021-09-05 14:14:32

            wpf如何将图片设置为窗体的背景

            System.Drawing.Bitmap bitmap = global::WpfApplication1.Properties.Resources.bg;
            ImageSourceConverter convert = new ImageSourceConverter();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            ImageBrush b = new ImageBrush();
            b.ImageSource = (ImageSource)convert.ConvertFrom(ms);
            this.Background = b;