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
void Gui_Main::setCaptureEnabled(bool enable)
{
/* start stop QBasicTimer FrameTimeLine; */
RRunning = enable;
if (enable && framerate > 32) {
FrameTimeLine.start(framerate,this);
} else {
FrameTimeLine.stop();
}
}
{
QPixmap small
= desktopscreen.
scaledToWidth(100);
devimg->paint( small );
scrollArea->setWidget(devimg);
delete &desktopscreen;
return small.toImage();
}
void Gui_Main::StartRead()
{
if (RRunning) {
StopRead();
return;
}
QString filename
= QFileDialog::getSaveFileName(this,
"Save animation",
"animation.mng",
"*.mng");
if (filename.size() > 0) {
animation = new AnimationWriter(filename,"MNG");
animation->setFrameRate(framerate);
animation->appendFrame(CatScreen());
setCaptureEnabled(true);
}
}
{
if (event->timerId() == FrameTimeLine.timerId()) {
timeline++;
qDebug() << "### timeline " << timeline;
animation->appendFrame(CatScreen());
}
}
void Gui_Main::StopRead()
{
setCaptureEnabled(false);
delete animation;
animation = 0;
}
void Gui_Main::setCaptureEnabled(bool enable)
{
/* start stop QBasicTimer FrameTimeLine; */
RRunning = enable;
if (enable && framerate > 32) {
FrameTimeLine.start(framerate,this);
} else {
FrameTimeLine.stop();
}
}
QImage Gui_Main::CatScreen()
{
QDesktopWidget *desk = qApp->desktop();
QPixmap desktopscreen = QPixmap::grabWindow(desk->screen()->winId());
QPixmap small = desktopscreen.scaledToWidth(100);
devimg->paint( small );
scrollArea->setWidget(devimg);
delete &desktopscreen;
return small.toImage();
}
void Gui_Main::StartRead()
{
if (RRunning) {
StopRead();
return;
}
QString filename = QFileDialog::getSaveFileName(this, "Save animation", "animation.mng", "*.mng");
if (filename.size() > 0) {
animation = new AnimationWriter(filename,"MNG");
animation->setFrameRate(framerate);
animation->appendFrame(CatScreen());
setCaptureEnabled(true);
}
}
void Gui_Main::timerEvent(QTimerEvent *event)
{
if (event->timerId() == FrameTimeLine.timerId()) {
timeline++;
qDebug() << "### timeline " << timeline;
animation->appendFrame(CatScreen());
}
}
void Gui_Main::StopRead()
{
setCaptureEnabled(false);
delete animation;
animation = 0;
}
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
Bookmarks