SDL从原始图像数据字符串绘制PNG图像 [英] SDL draw PNG image from raw image data string

查看:90
本文介绍了SDL从原始图像数据字符串绘制PNG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C ++的Windows 32位的SDL2项目中设置了PNG资源文件。

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);

result 变量包含以下所有字符PNG图像(如果已转换为字符串)。

The result variable contains all the characters of the PNG image (if it was converted to a string).

如何在 SDL图像并显示在窗口上?

How can I use this image string with SDL Image and display it on the window?

推荐答案

使用 SDL_RWFromConstMem(data,dataSize) 来创建一个针对内存的只读 SDL_RWops 并将其传递给 IMG_Load_RW()

这篇关于SDL从原始图像数据字符串绘制PNG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆