本文整理汇总了C#中System.Drawing.Color.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Color.GetHashCode方法的具体用法?C# Color.GetHashCode怎么用?C# Color.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Color
的用法示例。
在下文中一共展示了Color.GetHashCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPen
Pen GetPen(Color color, int width, bool dashed)
{
int hash = color.GetHashCode() ^ width.GetHashCode() ^ dashed.GetHashCode();
int debug1 = color.GetHashCode();
int debug2 = width.GetHashCode();
int debug3 = dashed.GetHashCode();
Pen pen;
if (!PenCache.TryGetValue(hash, out pen))
{
pen = new Pen(color, width);
if (dashed)
pen.DashPattern = new float[] { 3, 6 };
PenCache[hash] = pen;
}
return pen;
}
示例2: FindClosestEntry
/// <summary>
///
/// </summary>
/// <param name="clr"></param>
/// <returns></returns>
public int FindClosestEntry(Color clr)
{
// If not sure of consistency with palette, clear the hash table
if (m_fClearHash)
m_htbl.Clear();
// Is this mapping available already?
int key = clr.GetHashCode();
if (m_htbl.ContainsKey(key))
return (int)m_htbl[key];
// Find the entry, the long way
int nLowest = 256 * 256 * 3;
int iLowest = 0;
int nR = clr.R;
int nG = clr.G;
int nB = clr.B;
for (int iclr = 0; iclr < m_aclr.Length; iclr++) {
Color clrPal = m_aclr[iclr];
int dR = clrPal.R - nR;
int dG = clrPal.G - nG;
int dB = clrPal.B - nB;
int nD = dR * dR + dG * dG + dB * dB;
if (nD < nLowest) {
nLowest = nD;
iLowest = iclr;
}
}
// Add it to the hash table and return it
m_htbl.Add(key, iLowest);
return iLowest;
}