qt - 模糊效果小部件

标签 qt photoshop transparent blurry

Photoshop中有没有一种方法可以为具有透明模糊效果的小部件创建一个按钮/矩形,以便它通过矩形显示背景图像,但它是模糊的?

比如这个越狱周的例子:enter image description here

我尝试使用不透明度使其透明,但我不确定如何实现这种模糊的外观。

最佳答案

这里是 QImage 快速模糊的代码片段,只需模糊背景一次并将其设置为背景

QImage MainWindow::blurred(const QImage& image, const QRect& rect, int radius, bool          alphaOnly)
{
int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
int alpha = (radius < 1) ? 16 : (radius > 17) ? 1 : tab[radius-1];

QImage result = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
int r1 = rect.top();
int r2 = rect.bottom();
int c1 = rect.left();
int c2 = rect.right();

int bpl = result.bytesPerLine();
int rgba[4];
unsigned char* p;

int i1 = 0;
int i2 = 3;

if (alphaOnly)
i1 = i2 = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);

for (int col = c1; col <= c2; col++) {
    p = result.scanLine(r1) + col * 4;
    for (int i = i1; i <= i2; i++)
        rgba[i] = p[i] << 4;

    p += bpl;
    for (int j = r1; j < r2; j++, p += bpl)
        for (int i = i1; i <= i2; i++)
            p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}

for (int row = r1; row <= r2; row++) {
    p = result.scanLine(row) + c1 * 4;
    for (int i = i1; i <= i2; i++)
        rgba[i] = p[i] << 4;

    p += 4;
    for (int j = c1; j < c2; j++, p += 4)
        for (int i = i1; i <= i2; i++)
            p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}

for (int col = c1; col <= c2; col++) {
    p = result.scanLine(r2) + col * 4;
    for (int i = i1; i <= i2; i++)
        rgba[i] = p[i] << 4;

    p -= bpl;
for (int j = r1; j < r2; j++, p -= bpl)
    for (int i = i1; i <= i2; i++)
        p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}

for (int row = r1; row <= r2; row++) {
    p = result.scanLine(row) + c2 * 4;
    for (int i = i1; i <= i2; i++)
        rgba[i] = p[i] << 4;

    p -= 4;
    for (int j = c1; j < c2; j++, p -= 4)
        for (int i = i1; i <= i2; i++)
            p[i] = (rgba[i] += ((p[i] << 4) - rgba[i]) * alpha / 16) >> 4;
}

return result;
}

关于qt - 模糊效果小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16269379/

相关文章:

java - 使位图的触摸区域变为透明

java - 在 libgdx 中使用filledcircle和pixmap

c++ - Qt 如何处理信号和槽的引用调用?

Qt QGraphicsView 不显示场景

c++ - 使用 QObject 属性的指针

html - 寻找第三方照片库

html - Photoshop 和 CSS3 背景阴影

javascript - 如何检查 Action 是否已经加载到 photoshop Action 调色板中?

linux - 将 Canvas 大小裁剪为透明 png 文件中可见图像大小的脚本

c++ - C++ 中的 Qt3d 输入