gpt4 book ai didi

使用 cairo 库创建高光效果

转载 作者:太空宇宙 更新时间:2023-11-04 02:14:13 29 4
gpt4 key购买 nike

我有一个 cairo_t cr,我可以用它来使用 cairo。我想尝试在这个 cairo 图形上创建一个突出显示效果,它应该执行以下操作之一:

  • 调亮整个图像,使其看起来更亮一些
  • 将背景,即图像的透明部分更改为更亮的颜色(例如白色)
  • 也许在背景上添加一点模糊

我如何使用 cairo 做到这一点?

[编辑] 我有一个显示图标的小部件,我想在将鼠标移到该小部件上时突出显示它。除了突出显示之外,我还想绘制一些白色背景,以便更清楚地突出显示哪个图标。 [/编辑]

最佳答案

我认为您应该查看 cairo 的一些运算符:

http://cairographics.org/operators/

使用 SOFT_LIGHT 或 LIGHTEN 和明亮的源颜色应该可以使整个图像变亮。我猜。我将对此做一些实验。

为什么要更改图像的透明部分?我猜大多数表面都没有任何透明部分。无论如何,我认为带有白色源的 DEST_OVER 应该做到这一点。

模糊处理是 cairo 无法为您做的。但是,您可以将图像绘制到图像表面,并使用互联网上流传的一些代码来模糊它。例如,谷歌就这样引导我:http://taschenorakel.de/mathias/2008/11/24/blur-effect-cairo/

编辑:我做了一些实验(这是 oocairo lua 绑定(bind),http://oocairo.naquadah.org/)。我认为您希望运营商 CAIRO_OPERATOR_ATOP 具有可靠的来源,例如RGBA(1、1、1、0.25)。这似乎确实使图像变亮了。


oocairo = require("oocairo")

s = oocairo.image_surface_create("argb32", 600, 400)
img = oocairo.image_surface_create_from_png("/usr/share/icons/wesnoth-1.8-icon.png")
local w, h = img:get_width(), img:get_height()

cr = oocairo.context_create(s)

function before()
cr:save()
cr:rectangle(0, 0, w, h)
cr:clip()
cr:set_source(img)
cr:paint()
end
function after()
cr:restore()
cr:translate(w, 0)
end

function try_operator(op, alpha)
before()
cr:set_operator(op)
cr:set_source_rgba(1, 1, 1, alpha)
cr:paint()
after()
end

function try_alpha(alpha)
cr:save()
before()
after()
try_operator("atop", alpha)
try_operator("color-dodge", alpha)
try_operator("soft-light", alpha)
try_operator("hard-light", alpha)
try_operator("hsl-hue", alpha)
try_operator("hsl-saturation", alpha)
try_operator("hsl-color", alpha)
try_operator("hsl-luminosity", alpha)
cr:restore()
cr:translate(0, h)
end

try_alpha(1)
try_alpha(0.75)
try_alpha(0.5)
try_alpha(0.25)
try_alpha(0)

s:write_to_png("/tmp/t.png")

关于使用 cairo 库创建高光效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9955964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com