SDL draw PNG image from raw image data string

扶醉桌前 提交于 2019-12-11 17:46:07

问题


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?


回答1:


Use SDL_RWFromConstMem(data, dataSize) to create a read-only memory-targeted SDL_RWops and pass that in to IMG_Load_RW().



来源:https://stackoverflow.com/questions/46136794/sdl-draw-png-image-from-raw-image-data-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!