is this alright..?

2008-05-12
2013-05-02
  • I want to open, mod the file and save it again..
    Is this the right code??

    //Other Fucntiosn

    ILboolean SaveFunction(char *FileName)
    {
        // Open file here

        fwrite(ilGetData(), 1,     ilGetInteger(IL_IMAGE_SIZE_OF_DATA), File);

        // Close file here

        return IL_TRUE;
    }
    void RegisterSaveFunction(void)
    {
        ilRegisterSave("xxx", SaveFunction);
        return;
    }

    ILubyte *Lump;
    ILuint Size;
    GLuint ShowMe;
    FILE *File;

    //Init
    ilInit();

    //Load
    File = fopen("input.jpg", "rb");
    fseek(File, 0, SEEK_END);
    Size = ftell(File);

    Lump = (ILubyte*)malloc(Size);
    fseek(File, 0, SEEK_SET);
    fread(Lump, 1, Size, File);
    fclose(File);

    ilLoadL(IL_JPG, Lump, Size);
    free(Lump);

    //Modify the Image
    ilSetPixels

    //Show
    ShowMe = ilutGLBindTexImage().

    //Save
    SaveFunction("Outputfile.jpg");

    Can this library do that?

     
    • Hi,

      it's easier if you do

      ilLoadImage("image.png").

      /* convert image by converting memory returned by ilGetData() here */
      /* (you might want to convert it to rgba first) */

      ilSaveImage("output.png");

      Don't forget to call ilInit() somewhere at the start of your program.

      But loading an image, modifiying it, and saving it again is definitely possible with DevIL.