Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Creat load and write PNG 16Bit grayscale pics

Help
steff
2011-03-27
2013-05-02
  • steff
    steff
    2011-03-27

    I want to create a grayscale iamge from height values from scratch with devil. Save them as an 16bit png to have 65 000 values per pixel for height information. And then load them again, read out the pixels and set the height values.

    If get devil to run in my app nter VS2010 and can creat and write a png to disk. But its

    1. only 8 bit and
    2. black.

    Meens i havend found the correct way to change the image data.

    Thats what i have so fare. 
    Can someone help me to find out how to write now values into the data block and save them to an 16bit PNG grayscale?
    Excuse my bad english ;)
        GLfloat* data = new GLfloat[272*272*3];
        ilInit();
        ILuint ImageName; // The image name.
        ilGenImages(1, &ImageName); // Grab a new image name.
        ilBindImage(ImageName); // bind it
        ilTexImage(272,272,1,3,IL_RGB,IL_UNSIGNED_BYTE,NULL);
        ilSetData(data);
        ilEnable(IL_FILE_OVERWRITE);
        ilSave(IL_PNG, "monkey.png");
    
     
  • steff
    steff
    2011-05-06

    I have now changed my code to the following.
    Writing the image works now but its still 8 and not 16bit.
    Any Idea?

        // create the image and write to disc.
        GLfloat* data = new GLfloat[272*272];
        ilInit();
    
        int width  = 272 ;
        int height = 272 ;
        int bytesToUsePerPixel = 24 ;  // 16 bit per channel
        int sizeOfByte = sizeof( unsigned char ) ;
        int theSize = width * height * sizeOfByte * bytesToUsePerPixel ;
        unsigned char * imData =(unsigned char*)malloc( theSize ) ;
        // write the height data to the image array
        for( int i = 0 ; i < theSize ; i++ )
        {
            imData[ i ] = 0 ;
        }
        ILuint ImageName; // The image name.
        ilGenImages(1, &ImageName); // Grab a new image name.
        ilBindImage(ImageName); // bind it
        ilTexImage(width,height,1,bytesToUsePerPixel,GL_LUMINANCE,IL_UNSIGNED_BYTE,NULL);
        //ilSetData(imData);
        ilEnable(IL_FILE_OVERWRITE);
        ilSave(IL_PNG, getCurrentHeightmapPath().c_str());
        free(imData);
    

    {