Storing WPF Image Resources

后端 未结 10 2012
眼角桃花
眼角桃花 2020-11-22 11:17

For a WPF application which will need 10 - 20 small icons and images for illustrative purposes, is storing these in the assembly as embedded resources the right way to go?

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 11:44

    The following worked and the images to be set is resources in properties:

        var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(MyProject.Properties.Resources.myImage.GetHbitmap(),
                                          IntPtr.Zero,
                                          Int32Rect.Empty,
                                          BitmapSizeOptions.FromEmptyOptions());
        MyButton.Background = new ImageBrush(bitmapSource);
    img_username.Source = bitmapSource;
    

提交回复
热议问题