Qt hasn t a initiative blurfil。 我研究了<代码>QGraphicsBlurEffect;它使用<代码>QPixmapBlurEffect,该编码本身使用一个称为<代码>expblur的内部助手方法(对应)。
expblur
itself uses a one-dimensional blur effect (motion blur in X direction, method qt_blurrow
) twice. It rotates the image between the two blurs by 90 degrees and afterwards rotates it back.
实际上, Qt has 动议模糊不清,但只是内部的。 因此,你需要写自己的效果。 为此,请参阅<代码>qt_blurrrow,可在<代码>上的Qt来源中找到。 这将为过滤器提供良好的质量,因为过滤器是一种超标的过滤器,而不是一条线。
If you don t want to go so deep into the Qt source code, take this pseudo-code as a start:
foreach pixel (x, y) in image {
for dx = -r to r with x+dx within image {
for dy = -r to r with y+dy within image {
Add pixel (x+dx, y+dy) of the source image with ↩
factor (matrix[dx, dy]) to the target image.
}
}
}
where matrix might be defined like this (for horizontal motion blur with radius 2):
0 0 0 0 0
0 0 0 0 0
0.1 0.2 0.4 0.2 0.1
0 0 0 0 0
0 0 0 0 0
通知说,所有条目的总和必须是1个,或你必须按矩阵条目的总和分立。
如果你想允许对α的任意gle角(而不仅仅是90度步骤),就很难为特定rad和角状α建立这一矩阵。 [EDIT:见关于这种矩阵的轻松生成的第3号一般性意见。]