我可以在 Qt 的角点处使用给定颜色的矩形区域中构建颜色渐变吗?

发布于 2025-01-20 11:47:16 字数 499 浏览 0 评论 0原文

我的颜色值矩阵均匀地散布在网格之间,它们之间有一些像素。类似的事情:

r _ _ g _ _ r ......
_ _ _ _ _ _ _ .....
_ _ _ _ _ _ _ ....
b _ _ r _ _ g ....
_ _ _ _ _ _ _ ....
_ _ _ _ _ _ _ ....
g _ _ b _ _ r ....
. . . . . . . ....
. . . . . . . ....
. . . . . . . .....

如何构造/绘制/绘制QT C ++颜色之间平滑过渡的梯度?我应该使用什么工具来实现这一目标?

我觉得,如果我在以下矩形中插入颜色值,我可以为整个网格做到这一点。 -

   r
  _ _ 
g _ _ r
  _ _
   b

但是,在这种情况下,qlineargradient,qradialGradient和qconicgradient似乎没有用,因为它们仅作为参数占据了两个点。

I have a matrix of values of colours evenly spread across a grid with some pixels in between them. Something like this:

r _ _ g _ _ r ......
_ _ _ _ _ _ _ .....
_ _ _ _ _ _ _ ....
b _ _ r _ _ g ....
_ _ _ _ _ _ _ ....
_ _ _ _ _ _ _ ....
g _ _ b _ _ r ....
. . . . . . . ....
. . . . . . . ....
. . . . . . . .....

How can I construct/draw/paint a gradient with smooth transition in between colours in Qt C++? What tools should I use to achieve this?

I feel that somehow if I interpolate the colour values in the following rectangle, I can do it for the whole grid. -

   r
  _ _ 
g _ _ r
  _ _
   b

But the classes QLinearGradient, QRadialGradient, and QConicGradient seem to be of no use in this scenario as they take only two points as arguments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉世弥音 2025-01-27 11:47:16

您可以使用双线性插值来计算每个单元格中点之间的颜色:

for any given point h find colors e and f
where r, g, and b chanel of e is equal to   
r(e) = r(a) + (r(b) - r(a)) * distance(a,e) / distance(a,b)
g(e) = ...
b(e) = ...

r(f) = r(c) + (r(d) - r(c)) * distance(c,f) / distance(c,d)
g(f) = ...
b(f) = ...

and then find r(h),g(h) and b(h) interpolating between e and f vertically

r(h) = r(e) + (r(f) - r(e)) * distance(e,h) / distance(e,f)
g(h) = ...
b(h) = ...

a-e---b
| h   |
| |   |
| |   |
c-f---d

You can use bilinear interpolation to calculate colors between points in each cell:

for any given point h find colors e and f
where r, g, and b chanel of e is equal to   
r(e) = r(a) + (r(b) - r(a)) * distance(a,e) / distance(a,b)
g(e) = ...
b(e) = ...

r(f) = r(c) + (r(d) - r(c)) * distance(c,f) / distance(c,d)
g(f) = ...
b(f) = ...

and then find r(h),g(h) and b(h) interpolating between e and f vertically

r(h) = r(e) + (r(f) - r(e)) * distance(e,h) / distance(e,f)
g(h) = ...
b(h) = ...

a-e---b
| h   |
| |   |
| |   |
c-f---d
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文