QT4 How to blur QPixmap image?

前端 未结 6 2053
遥遥无期
遥遥无期 2021-01-06 02:21

QT4 How to blur QPixmap image?

I am looking for something like one of the following:

Blur(pixmap); 
painter.Blur(); 
painter.Blur(rect);
         


        
6条回答
  •  旧时难觅i
    2021-01-06 02:39

    Add python code based on @Петър Петров answer for QT 5.

    def applyEffectToImage(src, effect):
        scene = QGraphicsScene()
        item = QGraphicsPixmapItem()
        item.setPixmap(QPixmap.fromImage(src))
        item.setGraphicsEffect(effect)
        scene.addItem(item)
        res = QImage(src.size(), QImage.Format_ARGB32)
        res.fill(Qt.transparent)
        ptr = QPainter(res)
        scene.render(ptr, QRectF(), QRectF(0,0, src.width(), src.height()) )
        return res
    
    blur = QGraphicsBlurEffect()
    blur.setBlurRadius(8)
    source = QImage(r"C:\Users\fran\Desktop\test.png")
    result = applyEffectToImage(source, blur)
    result.save(r"C:\Users\fran\Desktop\result.png")
    

提交回复
热议问题