Results 1 to 2 of 2

Thread: QPixmap being clipped after rotation

  1. #1
    Join Date
    Jan 2011
    Posts
    127
    Thanks
    42
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QPixmap being clipped after rotation

    Qt Code:
    1. QImage img("lena.jpg");
    2.  
    3. rotate_image_implace(img, angle); //rotate the img with angle degrees(90, 180, 270 and so on)
    4.  
    5. graph_scene_ = new QGraphicsScene(this);
    6. graph_scene_->addItem(graph_pixmap_ = new QGraphicsPixmapItem);
    7. graph_view_ = new QGraphicsView(graph_scene_, this);
    8.  
    9. graph_pixmap_->setPixmap(QPixmap::fromImage(img));
    10. graph_scene_->setSceneRect(img.rect());
    To copy to clipboard, switch view to plain text mode 

    type of graph_pixmap_ is QGraphicsPixmapItem

    type of graph_scene_ is QGraphicsScene

    type of graph_view_ is QGraphicsView

    This may clip the image if their height and width are different, how could I rotate the image without clipping it?

    Because the program need to save the image after rotating and mirror(vertical and horizontal), rotation of QGraphicsPixmapItem is not adopted.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,630
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPixmap being clipped after rotation

    You cannot rotate an x by y rectangular image without scaling and put it back into the same x by y space except in the limited case of a 180 degree rotation about the image centre. Assuming (because you have not shown us the code that you use to do this rotation) you are rotating about the centre of the x by y image then the rotated image will always fit in a square image sqrt(x*x + y*y) pixels on a side. Alternatively you can compute the minimal size of image you need to place the result in with simple trigonometry.

  3. The following user says thank you to ChrisW67 for this useful post:

    stereoMatching (25th November 2012)

Similar Threads

  1. Text clipped when rendering svg.
    By ocratato in forum Newbie
    Replies: 1
    Last Post: 20th June 2010, 10:03
  2. Line clipped on windows 7 at resolution 1280*1024
    By nikhil in forum Qt Programming
    Replies: 0
    Last Post: 9th June 2010, 11:29
  3. Creating clipped polygon
    By maverick_pol in forum Qt Programming
    Replies: 10
    Last Post: 27th August 2008, 23:15
  4. Replies: 5
    Last Post: 9th April 2007, 14:26
  5. QPainter clipped?
    By nikita in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 12:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.