I want to convert a "transparent" gif file to "transparent" png format? How can I do ?
// my fault code: It converts error because it changes the "transparent" part to "BLACK"
#include<stdlib.h> /* because of malloc() etc. */
int main(int argc, const char * argv)
ILuint handle, w, h;
/* First we initialize the library. */
/*Do not forget that… */
/* We want all images to be loaded in a consistent manner */
/* In the next section, we load one image */
ilGenImages(1, & handle);
ILboolean loaded = ilLoadImage( "1.gif");
if (loaded == IL_FALSE)
return -1; /* error encountered during loading */
/* Let’s spy on it a little bit */
w = ilGetInteger(IL_IMAGE_WIDTH); // getting image width
h = ilGetInteger(IL_IMAGE_HEIGHT); // and height
printf("Our image resolution: %dx%d\n", w, h);
/* how much memory will we need? */
int memory_needed = w * h * 4 * sizeof(unsigned char);
/* We multiply by 3 here because we want 3 components per pixel */
ILubyte * data = (ILubyte *)malloc(memory_needed);
/* finally get the image data */
ilCopyPixels(0, 0, 0, w, h, 1, IL_RGBA, IL_UNSIGNED_BYTE, data);
/* We want to do something with the image, right? */
for(i = 0; i < memory_needed; i++)
if(i % 31 == 0) /* vandalise the image */
data_ = i % 255;
/* And maybe we want to save that all… */
ilSetPixels(0, 0, 0, w, h, 1, IL_RGBA, IL_UNSIGNED_BYTE, data);
/* and dump them to the disc… */
/* Finally, clean the mess! */
ilDeleteImages(1, & handle);
free(data); data = NULL;
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.