本文介绍了有没有一种简单的方法来混合两个的System.Drawing.Color价值观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法来混合两个的System.Drawing.Color
值?还是我写我自己的方法采取两种颜色,并结合他们?
Is there an easy way to blend two System.Drawing.Color
values? Or do I have to write my own method to take in two colors and combine them?
如果我这样做,怎么可能一去的?
If I do, how might one go about that?
推荐答案
我写了一个实用的方法就是出于这样的目的。 :)
I wrote a utility method for exactly this purpose. :)
/// <summary>Blends the specified colors together.</summary>
/// <param name="color">Color to blend onto the background color.</param>
/// <param name="backColor">Color to blend the other color onto.</param>
/// <param name="amount">How much of <paramref name="color"/> to keep,
/// "on top of" <paramref name="backColor"/>.</param>
/// <returns>The blended colors.</returns>
public static Color Blend(this Color color, Color backColor, double amount)
{
byte r = (byte) ((color.R * amount) + backColor.R * (1 - amount));
byte g = (byte) ((color.G * amount) + backColor.G * (1 - amount));
byte b = (byte) ((color.B * amount) + backColor.B * (1 - amount));
return Color.FromArgb(r, g, b);
}
这篇关于有没有一种简单的方法来混合两个的System.Drawing.Color价值观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!