⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QImage Rotation and Translation

  • Hi, I have a grayscale image. There is a rectangular area in the image, but it must be rotated by 0.25 degrees.
    I used the following code:

    QTransform myTransform;
    myTransform.translate(-5, -5); // Now I want to read the rectangular area only, so I try to translate the upperleft point.
    MyImage = myImage.transformed(myTransform);

    In this code, rotation is okay, but translation is not, there is no change. I wonder why?
    And also, the upperleft coordinates of the rectangular area was 241, 212; what is the new upper coordinates after rotation?


  • Hi, your transformation might not be working as you want because of the results of such transformations applied to a image using QTransform and QImage::transformed.
    According to the documentation:
    @QImage QImage::transformed( const QTransform &matrix , Qt::TransformationModemode=Qt::FastTransformation

    "Returns a copy of the image that is transformed using the given transformation matrix and transformation mode.

    The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the image produced is the smallest image that contains all the transformed points of the original image. Use the trueMatrix() function to retrieve the actual matrix used for transforming an image.

    Unlike the other overload, this function can be used to perform perspective transformations on images."

    Also, to know the resulting vector position, multiply the rotation matrix and vector position (linear algebra). The info about the QTransform matrix is in the documentation. They show other things that might guide you to what you want (see "here":http://developer.qt.nokia.com/doc/qt-4.7/qtransform.html )

  • If you did not solve your problem and need some help, feel free :-)

Log in to reply