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. Saving rotated QImage
Qt 6.11 is out! See what's new in the release blog

Saving rotated QImage

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 3.7k 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.
  • H Offline
    H Offline
    Hensim
    wrote on last edited by
    #1

    Hi There,

    I have a Problem saving rotated QImages. I load an Image, rotate it by some angle and want to save the result.
    Unfortunately the results look very strange, either black or black & white patterns. (for 90° it works)

    Even when i rotate the image and cut out a rectangular part, saving this smaller part has the same problems.

    I somehow could not find any related problems.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hensim
      wrote on last edited by
      #2

      maybe i should post my code :)

      @
      QTransform trans;
      trans.rotate(45);
      QImage pic = m_currentImage.transformed(trans,Qt::SmoothTransformation);

      // n18 is a point in the original image, so i map it with trans and calculate borders of the rect used // later
      QPoint tl = (trans.map(n18.toPoint()) - QPoint(75,150));
      QPoint br = (trans.map(n18.toPoint()) + QPoint(75,150));

      QRect rec = QRect(tl,br);
      // this would cut out the rectangle, it also shows in my program as a perfect rectangle
      // pic = pic.copy(rec);

      QImageWriter w(QCoreApplication::applicationDirPath() + "/imagedat/blub.png","png");
      w.write(pic);@

      And the output picture does not look any familiar with the original image. Just totally weird.
      If i set the angle to 90° it outputs the right picture rotated by 90°.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hensim
        wrote on last edited by
        #3

        If anyone is interested in the Solution:

        I now tried to apply the transformation to the pixmap and converted back to QImage and this works!!!

        I still wonder why exactly this is the case.

        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