梯度算法..它是如何工作的
如果给我颜色 A 和颜色 B,如何才能避免在画布上生成渐变,然后将其转换为位图。
这样
public Bitmap makeGradient(Color from, Color to){}
真的会起作用吗?
我希望这不是太含糊。我感谢您的时间和精力。
诗。 stackoverflow 上有一个问题可以回答这个问题,但我仍然很困惑:(
这里是: 以编程方式生成渐变?
If I was given color A and color B, how can one go aboit generating a gradient on a canvas which can be later converted to a bitmap.
Such that
public Bitmap makeGradient(Color from, Color to){}
Would actually work?
I hope this is not too vague. I thankyou for your time and effort.
Ps. There is a question on stackoverflow that answers this but I amstill confused :(
Here it is: Generating gradients programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建径向渐变的一种方法可能是定义焦点以及渐变的范围,当生成图像时,您将计算当前像素和焦点之间的距离,将其除以渐变范围并将结果剪裁为 1。然后使用您链接的问题中的公式。
像这样的伪代码:
这意味着像素距离焦点越远,
firstCol
对它的贡献就越大(超出渐变范围的像素将仅使用firstCol< /code> 因为
factor
对于这些来说应该是1.0
)。One way to go about creating a radial gradient might be to define the focus point as well as the extent of the gradient and when you generate the image you'd calculate the distance between the current pixel and the focus point, divide it by the gradient extent and clip the result to 1. Then use the formula in the question you linked.
Something like this pseudocode:
This would mean that the farther a pixel is from the focus point the more
firstCol
will contribute to it (pixels that are outside the extent of the gradient will only usefirstCol
sincefactor
should be1.0
for those).