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. Rotate QImage but do not alter size dimensions etc

Rotate QImage but do not alter size dimensions etc

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 9.1k 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.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Hello Devs :)
    I am making an application and a part of it rotates an image and saves it back (replacing the original).
    This is my code:
    @QImage image(ui->listWidget->currentItem()->text());
    if(!QFile(ui->listWidget->currentItem()->text()).exists() || image.isNull())
    return;
    QTransform rot;
    rot.rotate(90);
    image = image.transformed(rot);
    image.save(ui->listWidget->currentItem()->text(), "JPG", 100);@
    So, this will rotate the image 90 degrees!
    If I run this code 4 times it should result to the initial image, but it doesn't. I can see major changes to the file size and image quality, even if the quality option is 100 (100%).

    So, I was wondering if it is possible to rotate an image without altering the dimensions (i don't know if this is happening) and mainly the quality of the image.
    For example, is it possible to have a 10002000 image, rotate it right 90 degrees and have a 20001000 image with exactly the same pixels as the initial? I mean the down left corner pixel to go up left corner, the next to it to follow etc without leaving back any pixel (if this was done I assume that this should result to the same image as the initial if the code was run 4 times but it doesn't)...
    Is this what the 100% quality does? I assume that no... How can I manage to do this?

    thanks in advance for any answers!

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

      AFAIK, even a quality option of 100 will not use lossless compression (it is defined within the JPEG standard but not widely supported). Also, since the original file is compressed, you won't reach the same (compressed) state again without the original (uncompressed) image.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on last edited by
        #3

        loladiro, thanks for the answer. I understood that it is not possible to do it via the way of the 1st post. Is there another way that takes the pixels one by one and place them using the way I described above or this is not possible using compressed formats like JPEG?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          There are functions for lossless rotation within libjepeg (and espacially the jpegtran command line utility). You might be able to use them.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alexandros
            wrote on last edited by
            #5

            Ok thanks!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              You could also might consider using .png images, which are lossless.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                alexandros
                wrote on last edited by
                #7

                I use both :) Thanks for informing me that PNG is lossless :)

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vivelu
                  wrote on last edited by
                  #8

                  Actually, you should use the high quality transformation. Now you are using the fast:

                  http://doc.qt.nokia.com/4.7/qimage.html#transformed
                  http://doc.qt.nokia.com/4.7/qt.html#TransformationMode-enum

                  So, calling:
                  @
                  image = image.transformed(rot, Qt::SmoothTransformation);
                  @
                  is slower, but makes lots of better result.

                  So, even by saving into lossless image file didn't help, because the image data was 'broken' just after the first transformation.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mlong
                    wrote on last edited by
                    #9

                    vivelu: Thanks for your input, but please note this thread is over 4 months old. Please be aware that posting to ancient (by forum standards) posts is typically frowned upon.

                    Thanks!

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vivelu
                      wrote on last edited by
                      #10

                      mlong: Thanks for the warning.

                      I ended up here by google search and saw this topic had false or insufficient response to the problem stated. I kind of answered to myself and others who might be interested about Qt transformations. The more information about Qt is precise and complete, the more frowning I'm willing to accept =)

                      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