模糊效果小工具

时间:2013-04-29 00:00:01

标签: qt photoshop transparent blurry

在Photoshop中是否有办法为具有透明模糊效果的小部件创建按钮/矩形,以便通过矩形显示背景图像但是它模糊了?

例如在这个越狱推文的例子中:enter image description here

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

3 个答案:

答案 0 :(得分:1)

这是为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;
}

答案 1 :(得分:1)

我会用照片复制图层并删除你不想模糊的部分(或用面具隐藏它们)。使用模糊滤镜实现模糊效果。那张照片看起来像镜头模糊。转到过滤器&gt;模糊&gt;镜头模糊。在对话框中的滑块选项上,将“半径”滑块向右移动(大约24)。然后在顶部应用一个新图层,黑色矩形设置为大约15%的不透明度。只要黑色矩形和复制模糊照片的大小相同,并且图层锁定在一起,您就会获得模糊效果。看起来按钮会模糊背景。

答案 2 :(得分:0)

我认为你可以使用QGraphicsEffect拉一些东西。

您基本上可以将QGraphicsOpacityEffect应用于顶部窗口小部件,并将QGraphicsBlurEffect应用于基础窗口小部件。

阅读documentation以清楚了解。