Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105088

Can't rotate a QImage to 45 degrees by Y Axis

    XMLWordPrintable

Details

    • All
    • a6b55b3c46 (qt/qtbase/dev) a6b55b3c46 (qt/tqtc-qtbase/dev)

    Description

      I want to rotate the image to 45 degrees by Y axis, what should I do?

      bool func1()
      {
          QImage image(3840, 2160, QImage::Format_ARGB32_Premultiplied);
          image.fill(Qt::red);
      
          QTransform t;
          t.translate(image.width() / 2.0, image.height() / 2.0);
          t.rotate(-45, Qt::YAxis);
          t.translate(-image.width() / 2.0, -image.height() / 2.0);
          image = image.transformed(t);
      
          return image.save("/tmp/func1.png");
      }
      

      The func1 is output the "QImage: out of memory, returning null image" error message and return false. This behavior is related to the size of the image. If it is a 1000x1000 image, it can be successful. But the rotated image is different as use GIMP, is this a Qt bug?

      bool func2()
      {
          QImage image(3840, 2160, QImage::Format_ARGB32_Premultiplied);
          image.fill(Qt::red);
      
          QTransform t;
          t.translate(image.width() / 2.0, image.height() / 2.0);
      
          qreal b = qDegreesToRadians(-45);
          qreal sina = qSin(b);
          qreal cosa = qCos(b);
          QTransform tmp(cosa, 0, -sina / image.width(), // There is "-sina / 1024" in QTransform::rotate
                         0, 1, 0,
                         0, 0, 1);
      
          t = tmp * t;
          t.translate(-image.width() / 2.0, -image.height() / 2.0);
          image = image.transformed(t);
      
          return image.save("/tmp/func2.png");
      }
      

      The func2 is return true. I can't understand the QTransform::rotate, What is the "inv_dist_to_plane"? Why is its value 1/1024?

      Attachments

        1. func1-1000x1000-r45.png
          func1-1000x1000-r45.png
          10 kB
        2. func2-3840x2160-r45.png
          func2-3840x2160-r45.png
          52 kB
        3. gimp-1000x1000-r45.png
          gimp-1000x1000-r45.png
          13 kB
        4. gimp-3840x2160-r45.png
          gimp-3840x2160-r45.png
          56 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              zccrs JiDe Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes