Apparently, I’m not the only one having problems with IMG_Load_RW:----- Forwarded Message ----
From: “kidfruit at hotmail.com”
To: @Kevron_Rees
Sent: Friday, December 12, 2008 7:29:04 AM
Subject: About IMG_Load_RWActually I have the same problem.
When I use IMG_Load_RW to read the PNG picture directly ,it can complete
compiling but con’t show the picture and quickly flash and close. But IMG_Load
can do well if I unpack the picture to file. The same situation as you do with
JPEG file.Luckily? I found an solution with that. You can convert the file to bmp and pack
again, then you will find you can read the picture by IMG_Load_RW. But bmp is
too big so this is not the best method.I think there is something wrong in SDL_image lib, so maybe asking SDL official
is the best way.PS: If you find solution, hope you can share it to me, thanks
kidfruit
emai: kidfruit at gmail.com
Here is the code I’m using again:
For some reason IMG_Load_RW is reporting unsupported type however, if I
write it to a file, I can load it fine with a normal IMG_Load(). Any
hints on why it won’t load with IMG_Load_RW ?
Here’s the relevant code.
SDL_RWops * picData = SDL_RWFromMem(pic->picture().data(),pic->picture().size());
///temp write to disk to examine jpeg:
ofstream temppic;
temppic.open("/tmp/album-image.jpg",ios::binary | ios::trunc);
if(temppic)
{
///write to a file.
temppic.write(pic->picture().data(),pic->picture().size());
temppic.close();
}
if(!picData)
{
ndebug::out(ndebug::LOG_DEBUG,"SearchDir: failed to conver album art into SDL RWop for %s",path.c_str());
return NULL;
}
SDL_Surface * image;
/// This works:
image = IMG_Load("/tmp/album-image.jpg");
/// This doesn’t work:
//image = IMG_Load_RW(picData,1);
if(!image)
{
ndebug::out(ndebug::LOG_ERR,"SearchDir: Failed to load album art image. Error: (%s)",IMG_GetError());
ndebug::out(ndebug::LOG_ERR,"SearchDir: mime type of image: %s",pic->mimeType().toCString());
return NULL;
}
return image;