Results 1 to 8 of 8

Thread: Frame sequence

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Unhappy Frame sequence

    Hi all
    I am trying to load a sequence of images having .png extension similar to playing a video. I have described a text file which contains the absolute path of the images. Now I was able to open the text file and read line by line data using readLine function but when I try to display it in a loop using setPixmap function, only the path of the last line in the text is being displayed.Can anyone help me.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Frame sequence

    How do you swap frame next() pixmap you set a timer event? on frame total
    can you post this piece of code?

  3. #3
    Join Date
    Apr 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Frame sequence

    Its a long time since ive done things like this, but you may need to tell whatever it is to redraw itself. update() ?

  4. #4
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Exclamation Re: Frame sequence

    There are two files
    window.h
    Qt Code:
    1. #ifndef UI_WINDOW_H
    2. #define UI_WINDOW_H
    3.  
    4. #include <QtGui>
    5.  
    6. class QSplitter;
    7.  
    8. class Custom_window : public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. Custom_window();
    14.  
    15. private slots:
    16. void new_dialog();
    17. private:
    18. QPushButton *createButton(const QString &text,QWidget *receiver,
    19. const char *member);
    20. void Button_Layout();
    21.  
    22. QLabel *old_window;
    23. QPushButton *start;
    24. QPushButton *stop;
    25. QVBoxLayout *mainLayout;
    26. QGridLayout *buttonsLayout;
    27. QLabel *address;
    28. QLineEdit *url;
    29. QSpacerItem *spacerItem;
    30. QTextEdit *message;
    31. QFile *file;
    32. QPixmap *p;
    33. };
    34. #endif
    To copy to clipboard, switch view to plain text mode 
    window.cpp
    Qt Code:
    1. #include<QtGui>
    2. #include<stdio.h>
    3.  
    4. #include "window.h"
    5.  
    6. Custom_window::Custom_window()
    7. {
    8. old_window = new QLabel;
    9. old_window->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    10. old_window->setAlignment(Qt::AlignCenter);
    11. old_window->setText("Press Start");
    12. address = new QLabel;
    13. address->setText("Server I.P");
    14. QFont font;
    15. font.setPointSize(11);
    16. address->setFont(font);
    17. url = new QLineEdit;
    18. url->setObjectName(QString::fromUtf8("url"));
    19. message = new QTextEdit;
    20. message->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
    21. Button_Layout();
    22.  
    23. mainLayout = new QVBoxLayout;
    24. mainLayout->addWidget(old_window);
    25. mainLayout->addLayout(buttonsLayout);
    26. mainLayout->addWidget(message);
    27. setLayout(mainLayout);
    28. setWindowTitle(tr("Client GUI"));
    29. resize(640,800);
    30. }
    31.  
    32. QPushButton *Custom_window::createButton(const QString &text,QWidget *receiver,
    33. const char *member)
    34. {
    35. QPushButton *button = new QPushButton(text);
    36. button->connect(button,SIGNAL(clicked()),receiver,member);
    37. return button;
    38. }
    39.  
    40. void Custom_window::Button_Layout()
    41. {
    42. start = createButton(tr("Start"), this, SLOT(new_dialog()));
    43. stop = createButton(tr("Stop"), this, SLOT(close()));
    44. buttonsLayout = new QGridLayout;
    45. buttonsLayout->addWidget(address,0,0,1,1);
    46. buttonsLayout->addWidget(url,0,1,1,1);
    47. buttonsLayout->addWidget(start,0,2,1,1);
    48. buttonsLayout->addWidget(stop,0,3,1,1);
    49.  
    50. }
    51.  
    52. void Custom_window::new_dialog()
    53. {
    54. QFile file("in.txt");
    55. if (!file.open(QIODevice::ReadOnly | QIODevice::Text ))
    56. return;
    57. QTextStream in(&file);
    58. while (!in.atEnd()) {
    59. QString line = in.readLine();
    60. url->setText(line);
    61. QPixmap p(line);
    62. p=p.scaled ( old_window->width(),old_window->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
    63. old_window->resize(500,480);
    64. old_window->setPixmap(p);
    65. message->append("The path of the file is");
    66. message->append(line);
    67. }
    68. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 22nd May 2008 at 21:20. Reason: missing [code] tags

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Frame sequence

    And how you define time to display one pixmap?
    If you open 100 file by setpixmap you can see only the last!

    You must create a data struct from image

    Qt Code:
    1. struct frame
    2. {
    3. QByteArray extension; /* png jpg ...*/
    4. QByteArray data; /* pixmap data */
    5. int timetolive; /* time to show */
    6. QRect display; /* 100x100 */
    7. int age;
    8. };
    To copy to clipboard, switch view to plain text mode 

    or better make a struct like MNG image format and you can display on QMovie

    or have a look on
    http://wiki.qtcentre.org/index.php?t..._types_with_Qt
    or other image class to serialize image:
    http://www.qtforum.de/forum/viewtopic.php?t=6600

    After create a QDataStream wo contain all your single frame the virtual AVI file
    and at end play its... from a timer event

    if your choise the MNG format all needed info is inside:
    QDIR\4.4.0_src\src\3rdparty\libmng

  6. #6
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: Frame sequence

    Can u be more specific i.e where can I place the data struct. Plz post the code also

  7. #7
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Frame sequence

    Here is a good structure to compose image frame:

    qt-x11-opensource-4.0.0-b2/tools/qvfb/qanimationwriter.cpp
    It is as target only linux but i rewrite it to win32

    http://fop-miniscribus.googlecode.co...emo_write_mng/

    Compose image sequence

    Qt Code:
    1. void Gui_Main::setCaptureEnabled(bool enable)
    2. {
    3. /* start stop QBasicTimer FrameTimeLine; */
    4. RRunning = enable;
    5. if (enable && framerate > 32) {
    6. FrameTimeLine.start(framerate,this);
    7. } else {
    8. FrameTimeLine.stop();
    9. }
    10. }
    11. QImage Gui_Main::CatScreen()
    12. {
    13. QDesktopWidget *desk = qApp->desktop();
    14. QPixmap desktopscreen = QPixmap::grabWindow(desk->screen()->winId());
    15. QPixmap small = desktopscreen.scaledToWidth(100);
    16. devimg->paint( small );
    17. scrollArea->setWidget(devimg);
    18. delete &desktopscreen;
    19. return small.toImage();
    20. }
    21.  
    22. void Gui_Main::StartRead()
    23. {
    24. if (RRunning) {
    25. StopRead();
    26. return;
    27. }
    28. QString filename = QFileDialog::getSaveFileName(this, "Save animation", "animation.mng", "*.mng");
    29. if (filename.size() > 0) {
    30. animation = new AnimationWriter(filename,"MNG");
    31. animation->setFrameRate(framerate);
    32. animation->appendFrame(CatScreen());
    33. setCaptureEnabled(true);
    34. }
    35. }
    36. void Gui_Main::timerEvent(QTimerEvent *event)
    37. {
    38. if (event->timerId() == FrameTimeLine.timerId()) {
    39. timeline++;
    40. qDebug() << "### timeline " << timeline;
    41. animation->appendFrame(CatScreen());
    42. }
    43. }
    44. void Gui_Main::StopRead()
    45. {
    46. setCaptureEnabled(false);
    47. delete animation;
    48. animation = 0;
    49. }
    To copy to clipboard, switch view to plain text mode 


    try it
    1# svn co http://fop-miniscribus.googlecode.co...emo_write_mng/ movietest
    2#
    copy path from QTDIR /src/3rdparty/zlib & libpng to movietest dir

    INCLUDEPATH += ui libpng zlib

    and build it...

    it write file .... but QMovie on read say:
    MNG error 4097: Image is larger than defined maximum; chunk MHDR; subcode 0:0
    MNG error 1028: Chunk-length is invalid; chunk MOVE; subcode 0:0

    MHDR is a chunk format to learn and after you can register your image to a simple movie like gif animated ...

    to look original search qanimationwriter.cpp on http://www.google.com/codesearch

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Frame sequence

    Quote Originally Posted by bmn View Post
    Can u be more specific i.e where can I place the data struct. Plz post the code also

    QT 4.4 can write APNG image format!
    http://en.wikipedia.org/wiki/Animate...twork_Graphics


    I have it ready as console assembler now you can bundle all your image and display on firefox ...
    and later write a QLabel to display al single frame png....

    Qt Code:
    1. apng img1.png img2.png img3.png [enter]
    To copy to clipboard, switch view to plain text mode 

    result here...

    Install Firefox 3 or GrandParadiso , Opera 9.5 if the image here is not animated and you see only the first frame....

    svn co http://fop-miniscribus.googlecode.co...PNG_assembler/ APNG_assembler

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. Load a sequence of frames
    By perseo in forum Qt Programming
    Replies: 9
    Last Post: 20th May 2008, 13:29
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. Using a frame for different functions
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 29th January 2008, 13:45
  5. Multi frame management ... is it possible ?
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 25th January 2006, 10:41

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.