Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Load and save image - file size drastically reduced
QtWS25 Last Chance

Load and save image - file size drastically reduced

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 861 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gergnnud
    wrote on last edited by
    #1

    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";
        }@
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved