Lossless optimization of JPEG with FreeImage
===

There are several tools to create a optimize a JPEG without sacrificing quality. I've been looking for a way to do it through code (preferably in .NET) and I'm currently settled on FreeImage but I'm not getting the result I want.

There's an JPEG_OPTIMIZE flag but you have to set a quality flag as well and then it's not lossless anymore.

This is what I tried:

    var image = FreeImage.Load(FREE_IMAGE_FORMAT.FIF_JPEG, fileIn, FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE);
    FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JPEG, image, fileOut, FREE_IMAGE_SAVE_FLAGS.JPEG_OPTIMIZE | FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB);

That actually doubled the image size... Changing the flag changes the quality of the output file, I want it to be exactly the same. What's the proper way to do it?