【发布时间】:2011-11-12 09:26:24
【问题描述】:
我在 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);
【问题讨论】:
-
您的
load_image例程返回未初始化的 myimage。这只是一个错字,你真正的意思是SDL_Surface *myimage = SDL_DisplayFormat(temp);? -
我不明白你在说什么,但它停在 printf("IMG_Load_RW: %s\n", IMG_GetError());行并打印一个错误,所以我认为这与此无关
-
我指的是
SDL_Surface *myimage; image = SDL_DisplayFormat(temp); -
我们需要知道这条线是什么意思:
std::vector <std::string> buffer = c.data();具体你从哪里得到 c。关注数据!