gpt4 book ai didi

c++ - 如何使用内存中的 sdl 加载图像 (c++)

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:57:10 26 4
gpt4 key购买 nike

我在 std::vector<std::string> 中有一张图片多变的。我使用 winhttp 从网站下载图像 我成功写入文件并显示,但现在我想直接从内存中显示它。如何加载它?

我已经试过了,但它不起作用:

SDL_Surface *load_image(char * buff,int size) 
{
SDL_RWops *rw = SDL_RWFromMem(buff,size );
SDL_Surface *temp = IMG_Load_RW(rw, 1);

if (temp == NULL)
{
printf("IMG_Load_RW: %s\n", IMG_GetError());
system("pause");
exit(1);
}

//Convert the image to optimal display format
SDL_Surface *myimage;
image = SDL_DisplayFormat(temp);

//Free the temporary surface
SDL_FreeSurface(temp);

//Return our loaded image
return myimage;
}


std::vector <std::string> buffer = c.data();
std::string str_buffer =buffer[0];

for( size_t i =1;i<buffer.size();++i)
{
str_buffer+=buffer[i];
};

image = load_image(const_cast<char*>(str_buffer.c_str()),str_buffer.length()+1);

最佳答案

我不是 100% 确定,但看起来你应该可以这样说:

std::vector<char> the_image; // populate somehow

SDL_Surface * s = load_image(the_image.data(), the_image.size());

在较旧的编译器中,您可能必须为第一个参数使用 &the_image[0] 来代替 data()

关于c++ - 如何使用内存中的 sdl 加载图像 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8101442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com