I've setup a PNG resource file in my SDL2 project for Windows 32bit in C++.
HRSRC hRes = FindResource(0, MAKEINTRESOURCE(IMGID), "PNG");
if (!hRes) {
Log::Error("Find resource IMGID");
return;
}
HGLOBAL hData = LoadResource(0, hRes);
if (!hData) {
Log::Error("Load resource IMGID");
return;
}
DWORD dataSize = SizeofResource(0, hRes);
char* data = (char*)LockResource(hData);
std::string result;
result.assign(data, dataSize);
The result
variable contains all the characters of the PNG image (if it was converted to a string).
How can I use this image string with SDL Image and display it on the window?
Use
SDL_RWFromConstMem(data, dataSize)
to create a read-only memory-targetedSDL_RWops
and pass that in toIMG_Load_RW()
.