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. Image rotation - getting the best result
Forum Updated to NodeBB v4.3 + New Features

Image rotation - getting the best result

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    leo738
    wrote on last edited by
    #1

    Hello all,

    I'm using Qt Creator 4.11.0 Based on Qt 5.12.8 (GCC 9.3.0, 64 bit). My development at the moment is on a desktop machine but eventually it'll be moved to an embedded linux device.

    I have a label (circleLable) that contains a circular image (that is not smooth, i.e. irregular in parts of the circumference) that I'm trying to continuously & smoothly rotate on a stacked widget. The code I'm using to do this is:

    void MainWindow::rotateImage(){
        static int degrees = 0;
        degrees +=1;
      QPixmap pixmap(":/images/cicularImage.png");
       QMatrix rm;
        rm.rotate(degrees);
        pixmap = pixmap.transformed(rm);
        ui->circleLabel->setPixmap(pixmap);
    
    // Code below will be moved elsewhere to only invoke once
        ui->circleLabel->setScaledContents( true );
        ui->circleLabel->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
        
    }
    

    While the image is rotating initial results leave something to be desired. I'm going to continuing working on it to improve results but can anyone share the experience of how to get the best in this situation?
    A circular border around the image?
    Does the image file format have any bearing on the quality of the image rotated?
    Should I try an image without a transparent/ no background (if that is even possible)?
    Is embedding a video the best way to go to get smooth results?

    Thanks for looking and any help,

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leo738
      wrote on last edited by leo738
      #2

      Well, I've had some success.

      The image rotation is working OK, smooth enough. I used an online tool to crop the image in a circular manner.

      The issue is that the image is moving left & right within the Qlabel box/ frame. I have made the Qlabel the same size as the image but looks like there's more going on.

      From the documentation & searching it looks like 0,0 for an image is top left hand corner, so I applied the transform as follows without success:

      QTransform tr;
         tr.translate(width()/2, height()/2);
         tr.rotate(degrees);
         tr.translate(-width()/2, -height()/2);
         pixmap = pixmap.transformed(tr);
      
      O 1 Reply Last reply
      0
      • L Offline
        L Offline
        leo738
        wrote on last edited by leo738
        #3

        Image movement/wobble solved using:

        ui->labelName->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

        Also for me it turns out translation was unnecessary. So this gave satisfactory results (called every 10msec):

        void MainWindow::rotateImage(){
            static int degrees = 0;
            degrees +=1;
            if (degrees > 359) degrees = 0;
            QPixmap pixmap(":/images/circularCroppedImage.png");
            QTransform tr;
            tr.rotate(degrees);
            pixmap = pixmap.transformed(tr);
            ui->labelName->setPixmap(pixmap);
        }
        

        I had wanted to display text on top of the image but it seems its not possible (as least not easy) to display both a pixmap & text so I just placed another label on top.

        Hope this helps someone else out there!

        1 Reply Last reply
        2
        • L leo738

          Well, I've had some success.

          The image rotation is working OK, smooth enough. I used an online tool to crop the image in a circular manner.

          The issue is that the image is moving left & right within the Qlabel box/ frame. I have made the Qlabel the same size as the image but looks like there's more going on.

          From the documentation & searching it looks like 0,0 for an image is top left hand corner, so I applied the transform as follows without success:

          QTransform tr;
             tr.translate(width()/2, height()/2);
             tr.rotate(degrees);
             tr.translate(-width()/2, -height()/2);
             pixmap = pixmap.transformed(tr);
          
          O Offline
          O Offline
          ollarch
          wrote on last edited by ollarch
          #4

          The image center is

          (width() - 1) / 2.0
          (height() - 1) / 2.0
          

          as the image coordinates starts at (0,0) and ends at (width-1, height-1).

          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