简体   繁体   English

如何从资源文件(.rc文件)加载位图?

[英]How to load a bitmap from a resource file (.rc file)?

I am programming a simple game in visual studio and I have set up a resource file (.rc file) i am also using sdl2. 我正在Visual Studio中编写一个简单的游戏,并且我也使用sdl2设置了资源文件(.rc文件)。 I am wondering if there is a way to load or draw the bit maps located in the resource file. 我想知道是否有一种方法可以加载或绘制位于资源文件中的位图。 Thanks in advance 提前致谢

I am currently using this line: 我目前正在使用以下行:

HBITMAP hBtMpIMG = LoadBitmap((HINSTANCE)getModuleHandle(_T("Project 1.exe")), MAKEINTRESOURCE(IDB_BITMAP1));

How would I render the hBtMpIMG using sdl2? 如何使用sdl2渲染hBtMpIMG?

You can use the API: LoadBitmap to load a bitmap stored in the executable: 您可以使用API​​: LoadBitmap加载存储在可执行文件中的位图:

    case WM_CREATE:
    {
        HBITMAP hBtMpBall = LoadBitmap((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDB_BALL)); //Here we have to use the executable module to load our bitmap resource
        //this means that this resource "ball.bmp" is compiled and stored in the executable module"
        //however if you use loadimage you can ignore this module and makeit null because you are laoding from file

        if(!hBtMpBall)
            MessageBox(0,"ball.bmp not found!",0,0);
    }
    break;
  • In a resource file: .rc you may have like this: 在资源文件: .rc您可能会这样:

     #include "myres.h" IDB_BALL BITMAP DISCARDABLE "ball.bmp" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM