How to Load and Save Image to File?
-----------------------------------

HOOPS Luminate provides support for some of the most popular image file formats including JPEG, PNG and HDR.

The **JPEG** is a lossy format which gives very high compression ratio but only save images in RGB format (no alpha). The **PNG** format is a lossless format with smaller compression ratio than JPEG but with alpha support. Finally the **HDR** format must be the format of choice to save floating point images (32bit per component) with little lossless compression.

The image I/O methods are located in ``RED::ImageTools`` and work as follows:

.. rubric:: Save an Image

.. code:: cpp 
        
    // image2d is a pointer to a RED image implementing the RED::IImage2D interface.

    // Save the image to a JPEG file.
    RC_TEST( RED::ImageTools::Save( image2d, false, "./my_image.jpg", true, false, 0.8f ) );

    // Save the image to a PNG file.
    RC_TEST( RED::ImageTools::Save( image2d, false, "./my_image.png", false, false, 0.8f ) );

.. rubric:: Load an Image

.. code:: cpp 
        
    // image2d is a pointer to a RED image implementing the RED::IImage2D interface.

    // Get a pointer to the RED resource manager.
    RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
    RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();

    // Load the image from a HDR file to graphics card memory with target RECT.
    RC_TEST( RED::ImageTools::Load( image2d, "./my_image.hdr", RED::FMT_FLOAT_RGB, false, false, RED::TGT_TEX_RECT, iresmgr->GetState() ) );

.. note:: 
    
    You can also load or save images to .red files. In that case, the image is compressed with no loss and saved in its native pixel format (see :doc:`/tasks/ta_ca/ta_ca_image/tk_loading_and_saving_image_to_red_file` for more details). 
