Load and save image - file size drastically reduced
-
Can anybody help me to understand why the following generates a .jpg file of only 353KB from a 2MB source?
I thought I had found a simple solution with image->load and image->save but the image file size changes on a straight transfer?
'temp_file’ is the input file and ‘current_file’ is the result. (Obviously there are a number of other variables too.)
Any help would be apreciated.@ // Make directories if they don't exist
QDir mdir;
QString mdpath = path + project + "/" + camNo + "/" + yearMonth;
if(!mdir.exists(mdpath))
{
mdir.mkpath(mdpath);
qDebug() << “Directory Created";
}
else
{
qDebug() << “Directory Already Exists";
}// Save the image QString mfpath = path + project + "/" + camNo + "/" + yearMonth + "/" + current_file; QImage *image = new QImage(); if(!mdir.exists(mfpath)) { if(image->load(temp_file)) { image->save(mfpath); } qDebug() << "Image Project = "+project+" Image Saved"; } else { qDebug() << "Image Project = "+project+" Image Already Exists"; }@
-
JPG is a lossy format: it will always change size (and loose quality!) when you save it again. If you want to preserve the file data, use QFile::copy() instead. It will also be much faster.