1

ピクセルの色を同じ値で変更して、小さな (100x20) 画像をアニメーション化したいと考えています。たとえば、赤チャンネルの値をフレームごとに 1 ずつ増やしてから、元に戻します。画像にはアルファ チャネルがあり、アニメーション速度は 30 ~ 100 fps です (プラットフォームによって異なります。Linux では 30 で十分ですが、Windows ではスムーズに表示するには ~70 が必要です)。

私が知っているように、QImageで行うと描画が速くなりますが、表示はQPixmapでより速くなります。

4

1 に答える 1

2

私はQGraphicsEffects、sが好きQPropertyAnimationです。白は着色しませんが、黒は着色します。

#include <QLabel>
#include <QPixmap>
#include <QGraphicsColorizeEffect>
#include <QTimerEvent>
#include <QPropertyAnimation>
#include <QShowEvent>
#include <QDebug>

class Widget : public QLabel
{
    Q_OBJECT
    Q_PROPERTY(qreal redness READ getRedness WRITE setRedness)

public:
    Widget(QWidget *parent = 0)
    {
        QPixmap p(300, 300);
        p.fill(Qt::black);
        this->setPixmap(p);
        colorize = new QGraphicsColorizeEffect();
        colorize->setColor(Qt::red);
        redness = 0;
        colorize->setStrength(redness);
        this->setGraphicsEffect(colorize);

        animation = new QPropertyAnimation(this,"redness");
        animation->setDuration(2000);
        animation->setLoopCount(10);
        animation->setStartValue(0.0);
        animation->setEndValue(1.0);
        animation->setEasingCurve(QEasingCurve::CosineCurve);
        animation->start();
    }

    ~Widget(){}
    qreal getRedness()
    {
        return redness;
    }
    void setRedness(qreal val)
    {
        redness = val;
        colorize->setStrength(redness);
        this->update();
//        qDebug() << redness;
    }

public slots:
    void showEvent(QShowEvent *)
    {
        animation->start();
    }

private:
    qreal redness;
    QGraphicsColorizeEffect * colorize;
    QPropertyAnimation * animation;

};

ここにmain.cppがあります

#include <QApplication>
#include "widget.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}

それが役立つことを願っています。

于 2013-04-10T03:02:28.990 に答える