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
Forum Updated to NodeBB v4.3 + New Features

Saving rotated QImage

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.9k 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 14 Jun 2012, 12:11 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 14 Jun 2012, 20:38 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 15 Jun 2012, 12:09 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

        1/3

        14 Jun 2012, 12:11

        • Login

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