Results 1 to 8 of 8

Thread: Image split, rearrange. QLabel best way to display?

  1. #1
    Join Date
    Aug 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Image split, rearrange. QLabel best way to display?

    I have seen another post where someone wanted to split an image into 4 pieces, rearrange them and put back into display.

    I am interested in taking an image, removing the bottom pixel line, and moving it to the top of the image. I would like to have this in a loop so the picture is rotating from bottom to top continually (basically making an image marquee).

    I have had success in using QLabel to display the picture, using third party code to copy the bottom to top, save the file, then re-read the file into QLabel. However the process is slow and I am looking for a faster alternative.

    I thought I could use QImage::copy() but I don't understand how I can rearrange the copied portions and save as a new QImage for display.
    Last edited by fire; 11th August 2008 at 15:55.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Image split, rearrange. QLabel best way to display?

    Construct a target pixmap/image with appropriate size, open a painter on it and use QPainter::drawPixmap() or drawImage() with appropriate source and target rects.
    J-P Nurmi

  3. #3
    Join Date
    Aug 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image split, rearrange. QLabel best way to display?

    Thanks.

    Is there a way to create an image from two images? Or an image from a painter?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Image split, rearrange. QLabel best way to display?

    Quote Originally Posted by fire View Post
    Is there a way to create an image from two images?
    The same approach works. Construct an image and draw other images on it.

    Or an image from a painter?
    What do you mean?
    J-P Nurmi

  5. #5
    Join Date
    Aug 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image split, rearrange. QLabel best way to display?

    I don't see a public function of QImage which is similar to drawImage (being able to direct the data to a specific part of the array).



    After drawing two images to my QPainter object, can I convert the QPainter back into a QImage?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Image split, rearrange. QLabel best way to display?

    Quote Originally Posted by fire View Post
    I don't see a public function of QImage which is similar to drawImage (being able to direct the data to a specific part of the array).



    After drawing two images to my QPainter object, can I convert the QPainter back into a QImage?
    The whole point is to use yet another image as a paint device. In other words, open the painter on a target image. Then draw two images with QPainter and this way you'll have an image constructed from two images in the end.
    J-P Nurmi

  7. #7
    Join Date
    Aug 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image split, rearrange. QLabel best way to display?

    It is just not clicking for me... I don't understand how to do a paint event inside of a paint event. I have a timer set up so when it fires the bottom 10 lines are added to the top of the image, the rest of the image is moved down. I want "full_img" to be a QImage holding the last images painted. My problem is understanding how to have 2 paintEvents trigger off the timer. The problem is commented in the paintEvent method.
    Here is my code, three files:

    Qt Code:
    1. // myMI.h
    2. #include <QWidget>
    3. class MarqueeImage : public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. MarqueeImage(QWidget *parent = 0);
    8.  
    9. protected slots:
    10. void paintEvent(QPaintEvent *event);
    11.  
    12. private:
    13. QImage top_img; // top part of the image minus 10 lines
    14. QImage bot_img; // bottom 10 lines
    15. QImage *full_img; // temporary image
    16. int myheight; // height of image
    17. int mywidth; // width of image
    18. int line_shift; // bottom 10 lines
    19. };
    20.  
    21. // myMI.cpp
    22. #include “header.h”
    23. #include <QPainter>
    24. #include <QTimer>
    25.  
    26. MarqueeImage::MarqueeImage(QWidget *parent)
    27. : QWidget(parent)
    28. {
    29. mywidth = 200; //bitmap width
    30. myheight = 300; //bitmap height
    31. line_shift = 10; //number of lines being moved from bottom to top
    32.  
    33. full_img = new QImage();
    34. full_img->load(“mybmp.bmp”);
    35.  
    36. QTimer *timer = new QTimer(this);
    37. connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    38. timer->start(500);
    39. }
    40.  
    41. void MarqueeImage::paintEvent(QPaintEvent *)
    42. {
    43. QPainter painter(this);
    44. top_img = full_img->copy(0, 0, mywidth-1, myheight-shift-1);
    45. bot_img = full_img->copy(0, myheight-line_shift-1, mywidth-1, shift);
    46. painter.drawImage(0, 0, bot_img);
    47. painter.drawImage(0, shift, top_img);
    48.  
    49. // This is where it doesn’t work
    50. QPainter paint_all(full_img);
    51. paint_all.drawImage(0, 0, bot_img);
    52. paint_all.drawImage(0, shift, top_img);
    53.  
    54. }
    55.  
    56.  
    57. // main.cpp
    58. #include <QApplication>
    59. #include “header.h”
    60.  
    61. int main(int argc, char *argv[])
    62. {
    63. Qapplication app(argc, argv);
    64. MarqueeImage myMI;
    65. myMI.show();
    66. return app.exec();
    67. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Aug 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image split, rearrange. QLabel best way to display?

    Any suggestions on how to open a Qpainter on a QImage inside a paintEvent?

Similar Threads

  1. QLabel size, for image display
    By C167 in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2013, 16:09
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  3. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  4. QScrollArea display custom QLabel
    By spawnwj in forum Qt Programming
    Replies: 6
    Last Post: 6th December 2006, 03:38
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.