QT4如何模糊QPixmap图像?
QT4如何模糊QPixmap图像?
我正在寻找类似以下内容之一:
Blur(pixmap);
painter.Blur();
painter.Blur(rect);
执行此操作的最佳方法是什么?
QT4 How to blur QPixmap image?
I am looking for something like one of the following:
Blur(pixmap);
painter.Blur();
painter.Blur(rect);
What is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
1) 声明外部 QT 例程:
2) 使用:
1st) declare external QT routine:
2nd) Use:
让我们为这个主题做出贡献。从 Qt 5.3 开始,以下函数将帮助您将 QGraphicsEffect 应用于 QImage(并且不会丢失 alpha)。
使用此函数来模糊图像非常简单:
当然,您不需要保存它,这是只是一个有用的例子。
您甚至可以放置阴影:
请注意范围参数,它会向原始图像的所有侧面添加
extent
像素数,这对于不被截断的阴影和模糊特别有用。Let's contribute to this topic. As of Qt 5.3, following function will help you a lot with applying QGraphicsEffect to QImage (and not losing the alpha)
Them, using this function to blur your image is straightforward:
Of course, you don't need to save it, this was just an example of usefulness.
You can even drop a shadow:
And note the extent parameter, it adds
extent
number of pixels to all sides of the original image, especially useful for shadows and blurs to not be cut-off.看看这个:
Check out this:
方法 1a:抓住原始部分并自己动手。您需要足够熟悉位图和模糊算法才能自己实现模糊。如果您想要那种精度,这就是您要走的路。
方法 1b:谁需要原始位?您可以使用 image.pixel(x,y) 和 image.setPixel(x,y,color) 代替。这不会像 1a 那么快,但应该更容易理解和编码。
方法2:通过小部件或场景使用QGraphicsBlurEffect。这里的代码使用标签小部件:
根据需要进行调整。例如,我假设默认的图形模糊效果是可以接受的。我在我的项目中使用方法2。
Method 1a: grab the raw bits and do it yourself. You'll need to be sufficiently familiar with bitmaps and blurring algorithms to implement the blur yourself. If you want that sort of precision, this is the way to go.
Method 1b: who needs raw bits? You can use image.pixel(x,y) and image.setPixel(x,y,color) instead. This won't be as fast as 1a, but it should be a bit easier to understand and code.
Method 2: use a QGraphicsBlurEffect, through a widget or scene. The code here uses a label widget:
Tweak as needed. For example, I'm presuming the default graphics blur effect is acceptable. I'm using Method 2 in my project.
高斯模糊是创建模糊效果的简单方法。
编辑:瞧,我遇到了 Qt 的 QGraphicsBlurEffect 。在 Qt 4.6 中引入,它似乎完全符合您的要求。
A Gaussian blur is a simple way to create a blurring effect.
Edit: And lo, I came across Qt's QGraphicsBlurEffect. Introduced in Qt 4.6, it seems to do exactly what you want.
添加基于 QT 5 的 @Петър Петров 答案的 python 代码。
Add python code based on @Петър Петров answer for QT 5.