Qt之给图像添加效果QGraphicsEffect

QGraphicsEffect给图像元素添加模糊Blur,阴影DropShadow,着色Colorize,透明QPacity等效果。函数

QGraphicsEffect是全部效果类的父类。链接原图和最后输出图像的设置[好比QGraphicsView的视口]之间的渲染通道,而后实现效果。code

效果是Item的,不是Scene的blog

一、QGraphicsBlurEffect:模糊继承

QPixmap pixmap(":/resources/lena.png");
    QGraphicsPixmapItem *bg = m_scene.addPixmap(pixmap); //将图像画在m_scene上面

    m_effect = new QGraphicsBlurEffect; //能够模糊图像图形的渲染区域。模糊效果在产生焦点失调效果时很是有用
    m_effect->setBlurRadius(10); //设置模糊半径,默认模糊半径为5像素。越大越看不清楚
   // m_effect->setEnabled(false); //效果开关,若是false就不起做用;默认是true
    bg->setGraphicsEffect(m_effect); //是QGraphicsItem的成员函数而不是scene的成员函数,将效果直接添加到条目上

二、QGraphicsColorizeEffect:颜色渲染ci

setScene(&m_scene);  //当前QWidget窗口时继承QGraphicsView的
    
    QPixmap pixmap(":/resources/lena.png");
    QGraphicsPixmapItem *bg = m_scene.addPixmap(pixmap); //将图像画在m_scene上面

    m_effect = new QGraphicsColorizeEffect;
    m_effect->setColor(QColor(0, 192, 192));
    m_effect->setStrength(0.5); //0.0表示无效果,1.0表示彻底着色,默认1.0
    m_effect->setEnabled(true);

    bg->setGraphicsEffect(m_effect);

三、QGraphicsOpacityEffect设置透明度get

setScene(&m_scene);  //当前QWidget窗口时继承QGraphicsView的

    QPixmap pixmap(":/resources/lena.png");
    QGraphicsPixmapItem *bg = m_scene.addPixmap(pixmap); //将图像画在m_scene上面

    m_effect = new QGraphicsOpacityEffect;
    m_effect->setOpacity(0.1); // 0.0表示彻底透明[没有了],1.0表示彻底不透明,默认0.7
    m_effect->setEnabled(true);

    bg->setGraphicsEffect(m_effect);

四、QGraphicsDropShadowEffect。。。。。等待完善it

相关文章
相关标签/搜索