Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

c++ - SDL draw PNG image from raw image data string

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...