ILuint ih; // Image Handle
ILboolean res; // Result
UINT size; // Size in bytes of image buffer
ilEnable(IL_FILE_OVERWRITE);
ilGenImages(1, &ih);
ilBindImage(ih);
// R->bpp is "bits per pixel"
size = R->Width * R->Height * (R->bpp /8);
ilSetInteger( IL_IMAGE_WIDTH, R->Width );
ilSetInteger( IL_IMAGE_HEIGHT, R->Height );
ilSetInteger( IL_IMAGE_BITS_PER_PIXEL, R->bpp );
ilSetInteger( IL_IMAGE_BPP, (R->bpp/8)); // Bytes per pixel
ilSetInteger( IL_IMAGE_SIZE_OF_DATA, size);
res = ilSetData( R->Buffer ); // Buffer where image is
res = ilSave(IL_PNG, RF->name); // Save as PNG
ilDeleteImages(1, &ih);
DevIL Image Saving
Ok, I give up. The Image Library seems quite simple, and I got it to work to load jpg/png/tga files rather quickly, but for the life of me, I can't get it to save.
This is an outline of my code:
R->Buffer already has the image there, from a call to glReadPixels, which succeeds, as I can save to BMPs, etc.
The result of this is that the image file is saved as a 1x1 image...
Also, all the values passed are correct... i don't know if i'm missing something here...
As far as I know you can't set the width etc. using ilSetInteger - have a look at the DevIL codes...use ilTexImage instead.
Here's the code I use:
Here's the code I use:
bool GuiWin32::SystemSaveImageData(const char *pszFilename, GuiImageData &sData){ // Check parameters if (!pszFilename || !sData.pData) return true; // Get image typ ILenum nType; char szEnding[64]; GetFilenameEnding(pszFilename, szEnding); if ((nType = ilGetTypeLoad(szEnding)) == IL_TYPE_UNKNOWN) return true; // Unkown type! // Get the format int nFormat; switch (sData.nComponents) { case 1: nFormat = IL_LUMINANCE; break; case 3: nFormat = IL_RGB; break; case 4: nFormat = IL_RGBA; break; default: return true; } // DevIL variables ILuint ImageName; // Save the image ilEnable(IL_FILE_OVERWRITE); ilGenImages(1, &ImageName); ilBindImage(ImageName); ilTexImage(sData.nWidth, sData.nHeight, 1, sData.nComponents, nFormat, IL_UNSIGNED_BYTE, sData.pData); // Save image ilSave(nType, (const ILstring)pszFilename); // Check if everything was ok ILenum PossibleError = ilGetError(); if (PossibleError != IL_NO_ERROR) { ilDeleteImages(1, &ImageName); return true; } // Delete image ilDeleteImages(1, &ImageName); return false;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement