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. pixmap saving image with random size

pixmap saving image with random size

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • K Offline
    K Offline
    killown
    wrote on last edited by
    #1

    I am using the following code to take a pic from a webcam but the pixmap is saving the image with random size, and I would like to save it with 354, 472, does anyone know what's going on with pixamap.scaled?

    I am following this example https://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-example.html

    void Camera::processCapturedImage(int requestId, const QImage& img)
    {
    Q_UNUSED(requestId);
    QImage scaledImage = img.scaled(ui->viewfinder->size(),
                                    Qt::KeepAspectRatio,
                                    Qt::SmoothTransformation);
    
    ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage));
     QPixmap pixmap(QPixmap::fromImage(scaledImage));
     qDebug() << QCoreApplication::applicationDirPath();
    
     //create /image folder
     QString folder = QCoreApplication::applicationDirPath() + "/images";
     QString image = folder + "/new.jpg";
    
     qDebug() << QDir(folder).exists();
     if(!QDir(folder).exists())
     {
         QDir().mkdir(folder);
     }
     //
    
     //scale 3x4 pic
     pixmap.scaled(QSize(354, 472),  Qt::KeepAspectRatio);
     pixmap.save(image);
     emit enteredText(QString("Imagem Salva!"));
     this->close();
    
    
    // Display captured image for 4 seconds.
    displayCapturedImage();
    QTimer::singleShot(4000, this, SLOT(displayViewfinder()));
    }
    
    1 Reply Last reply
    0
    • thamT Offline
      thamT Offline
      tham
      wrote on last edited by tham
      #2

      I guess Qt::KeepAspectRatio is the reason, change it to Qt::IgnoreAspectRatio may solve this problem

      //according to document, IgnoreAspectRatio is default value
      //you do not need to specify it if you like
      pixmap.scaled(QSize(354, 472),  Qt::IgnoreAspectRatio);
      

      By the way, why create another pixmap?Why not just use the QImage(scaledImage) to save your picture?Thanks

      K 1 Reply Last reply
      1
      • thamT tham

        I guess Qt::KeepAspectRatio is the reason, change it to Qt::IgnoreAspectRatio may solve this problem

        //according to document, IgnoreAspectRatio is default value
        //you do not need to specify it if you like
        pixmap.scaled(QSize(354, 472),  Qt::IgnoreAspectRatio);
        

        By the way, why create another pixmap?Why not just use the QImage(scaledImage) to save your picture?Thanks

        K Offline
        K Offline
        killown
        wrote on last edited by
        #3

        @tham solved, thank you

        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