How can I crop an image in Qt ?

How can I crop an image in Qt ?

Asked on December 27, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    Crop an image in Qt:

    QRect rect(10, 20, 30, 40);
    QPixmap original('image.png');
    QPixmap cropped = original.copy(rect);
    

     click this link: QPixmap::copy

    QRect rect(10, 20, 30, 40);
    QImage original('image.png');
    QImage cropped = original.copy(rect);
    

     For more information check this link: QImage::copy

    Answered on December 27, 2018.
    Add Comment

    The initialize code is:

      QImage image("initial_image.jpg");
      QImage copy ;
      copy = image.copy( 0, 0, 128, 128);
      copy.save("cropped_image.jpg");
    

    They save the code file and  cut the  upper left corner 128x128px.

    Answered on December 27, 2018.
    Add Comment

    The answer is given:

    By using the  QPixmap  to the copy method and  number with a QRect to the certain  crop.

    Answered on December 27, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.