Properties.Resources not loading an image

前端 未结 2 803
悲哀的现实
悲哀的现实 2021-01-15 09:57

I have a game application in Visual Studio 2012 C#. I have all the .png images I am using in the Resources file of the project.

Have you any idea why I can access a

相关标签:
2条回答
  • 2021-01-15 10:13

    Found from: Properties.Resources the icon name does not appear in the intellisense

    You also need to add the icon to the Resources.resx file. Open it in Visual Studio and drag your icon into the Icons menu of the resx and it will become available.

    Also, see Adding and Editing Resources (Visual C#)

    0 讨论(0)
  • 2021-01-15 10:33

    You can get a reference to the image the following way:

    Image myImage = Resources.yourImage;
    

    If you want to make a copy of the image, you'll need to do the following:

    Bitmap bmp = new Bitmap(Resources.yourImage);
    

    Don't forget to dispose of bmp when you're done with it. If you don't know the name of the resource image at compile-time, you can use a resource manager:

    ResourceManager rm = Resources.ResourceManager;
    Bitmap yourImage = (Bitmap)rm.GetObject("yourImage");
    

    The benefit of the ResourceManager is that you can use it where Resources.myImage would normally be out of scope, or where you want to dynamically access resources. Additionally, this works for sounds, config files, etc.

    0 讨论(0)
提交回复
热议问题