如何镜像电影并反向播放?
How can I mirror a movie and play it in reverse?
我一直在尝试 QMovie 尝试镜像电影以及倒放电影。
对于镜像位,我尝试分配负宽度但无济于事。由于 QImage 确实为此提供了便利,我希望 QMovie 也能这样做。
QMovie 对象中似乎没有这些东西的任何设施,所以我想知道我是否可以将 QIODevice 操纵到 QMovie 对象而不是实现这一点,但这对我来说是全新的领域,我在文档中没有看到任何明显的东西可以实现镜像或反向播放。
开始的代码示例与 PySide 页面上的相同:
label = QLabel()
movie = QMovie("animations/fire.gif")
label.setMovie(movie)
movie.start()
如有任何想法,我们将不胜感激。
谢谢,
弗兰克
QMovie
没有提供设置当前图像的方法,所以你必须直接使用QImageReader
来反向播放(使用QImageReader::jumpToImage()
)。这不是很容易,因为一帧和下一帧之间的延迟可以改变,但是你可以调用 QImageReader::nextImageDelay()
.
要显示电影,您可以实现自己的小部件来根据需要绘制电影。
在paintEvent()
中你可以给painter设置一个transformation来获得镜像效果,然后绘制电影的当前图像。
示例:
void MyWidget::paintEvent(QPaintEvent * event)
{
QPainter painter(this);
painter.scale(-1, 1); // x-axis mirror
//here maybe you must adjust the transformation to center and scale the movie.
painter.drawImage(0, 0, currentImage);
}
要播放电影,您必须设置一个计时器来更改当前图像。
示例:
//you must create a timer in the constructor and connect it to this slot
void MyWidget::timeoutSlot()
{
int currentImageIndex;
//here you have to compute the image index
imageReader.jumpToImage(currentImageIndex);
currentImage = imageReader.read(); //maybe you want to read it only if the index is changed
update();
}
Here你可以找到一个widget子类的例子,有timer和painter转换
我一直在尝试 QMovie 尝试镜像电影以及倒放电影。 对于镜像位,我尝试分配负宽度但无济于事。由于 QImage 确实为此提供了便利,我希望 QMovie 也能这样做。 QMovie 对象中似乎没有这些东西的任何设施,所以我想知道我是否可以将 QIODevice 操纵到 QMovie 对象而不是实现这一点,但这对我来说是全新的领域,我在文档中没有看到任何明显的东西可以实现镜像或反向播放。 开始的代码示例与 PySide 页面上的相同:
label = QLabel()
movie = QMovie("animations/fire.gif")
label.setMovie(movie)
movie.start()
如有任何想法,我们将不胜感激。
谢谢, 弗兰克
QMovie
没有提供设置当前图像的方法,所以你必须直接使用QImageReader
来反向播放(使用QImageReader::jumpToImage()
)。这不是很容易,因为一帧和下一帧之间的延迟可以改变,但是你可以调用 QImageReader::nextImageDelay()
.
要显示电影,您可以实现自己的小部件来根据需要绘制电影。
在paintEvent()
中你可以给painter设置一个transformation来获得镜像效果,然后绘制电影的当前图像。
示例:
void MyWidget::paintEvent(QPaintEvent * event)
{
QPainter painter(this);
painter.scale(-1, 1); // x-axis mirror
//here maybe you must adjust the transformation to center and scale the movie.
painter.drawImage(0, 0, currentImage);
}
要播放电影,您必须设置一个计时器来更改当前图像。
示例:
//you must create a timer in the constructor and connect it to this slot
void MyWidget::timeoutSlot()
{
int currentImageIndex;
//here you have to compute the image index
imageReader.jumpToImage(currentImageIndex);
currentImage = imageReader.read(); //maybe you want to read it only if the index is changed
update();
}
Here你可以找到一个widget子类的例子,有timer和painter转换