A QImage
is storing the contents of an image, not its representation in a file. Thus, even if you "don't process" the image, you're still decompressing it on loading, and recompressing it into whatever format the filename implies.
If the image format uses lossy compression, you'll be likely degrading the image each time it gets loaded and re-saved - thus it should be avoided.
If the image format uses lossless compression, the compression factor is highly contents-dependent - your processing of the image will have impact on the image size.
If you wish to preserve file representation of an image, you should load the file into a buffer, and only operate on QImage
when you intend to change it. Thus:
QFile file(fileName);
if (! file.open(QIODevice::ReadOnly)) return false;
QByteArray imageData = file.readAll();
if (imageData.isEmpty()) return false;
file.close();
// process the image
QImage img;
QBuffer imageBuffer(&imageData);
imageBuffer.open(QIODevice::ReadOnly);
img.load(&imageBuffer, "JPG");
imageBuffer.close();
//
// process the image here
//
imageData.clear();
imageBuffer.open(QIODevice::WriteOnly);
img.save(&imageBuffer);
imageBuffer.close();
// save the image
QSaveFile file(fileName);
if (! file.open(QIODevice::WriteOnly)) return false;
file.write(imageData);