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?
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?
1st) declare external QT routine:
2nd) Use:
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.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.
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.
Check out this: