How to compress FIBITMAP using FreeImagePlus?

341 views Asked by At

I am using FreeImagePlus/FreeImage. I want to compress the bitmaps without saving them to HDD (files) using FreeImagePlus/FreeImage.

The given function FreeImage_save does compress but its main aim is to save that image into a file in hard drive.

I am interested in compression only. How can I do this?

1

There are 1 answers

0
tod On BEST ANSWER

The saveToMemory function does the job. Compress only can be implemented by using compress and save to memory, as following:

fipImage img;
img.load("file.jpg");       
if (!img.isValid()) 
    cout <<"could not read the input image" << endl;

//For compress only: save image to memory

fipMemoryIO memIO;

if(!img.saveToMemory(CompressionFormat[j], memIO, 0)); 
cout<< "could not compress image" << endl;

Now memIO contains the saved image in the given compression format.

In other words, raw image from memory is compressed and the output (compressed image) is put back to memory.