Dynamically adding and loading image from Resources in C#

后端 未结 5 1920
太阳男子
太阳男子 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:19

    You use this :

     Image2.Source = new Bitmap(
          System.Reflection.Assembly.GetEntryAssembly().
            GetManifestResourceStream("MyProject.Resources.myimage.png"));
    

    Or

    Image2.Source = new Bitmap(WindowsFormsApplication1.Properties.Resources.myimage);
    

    I do recommend the second one.

提交回复
热议问题