如何从资源文件(.rc 文件)加载位图?
How to load a bitmap from a resource file (.rc file)?
我正在 visual studio 编写一个简单的游戏,我已经设置了一个资源文件(.rc 文件),我也在使用 sdl2。我想知道是否有办法加载或绘制位于资源文件中的位图。提前致谢
我目前正在使用这条线:
HBITMAP hBtMpIMG = LoadBitmap((HINSTANCE)getModuleHandle(_T("Project 1.exe")), MAKEINTRESOURCE(IDB_BITMAP1));
如何使用 sdl2 渲染 hBtMpIMG?
您可以使用 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;
在资源文件中:.rc
你可能有这样的:
#include "myres.h"
IDB_BALL BITMAP DISCARDABLE "ball.bmp"
我正在 visual studio 编写一个简单的游戏,我已经设置了一个资源文件(.rc 文件),我也在使用 sdl2。我想知道是否有办法加载或绘制位于资源文件中的位图。提前致谢
我目前正在使用这条线:
HBITMAP hBtMpIMG = LoadBitmap((HINSTANCE)getModuleHandle(_T("Project 1.exe")), MAKEINTRESOURCE(IDB_BITMAP1));
如何使用 sdl2 渲染 hBtMpIMG?
您可以使用 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;
在资源文件中:
.rc
你可能有这样的:#include "myres.h" IDB_BALL BITMAP DISCARDABLE "ball.bmp"