Dynamically adding and loading image from Resources in C#

后端 未结 5 1928
太阳男子
太阳男子 2020-12-19 02:31

I have some images added to my solution, right now it is under the folder images\\flowers\\rose.png inside the solution explorer. I want a way to dynamically load this imag

5条回答
  •  一个人的身影
    2020-12-19 03:11

    The following works just fine for me:

    image.Source = new BitmapImage(new Uri("pack://application:,,,/YourAssemblyName;component/Resources/someimage.png", UriKind.Absolute));
    

    Also you should change the Build Action of your image from None to Resource.

提交回复
热议问题