【问题标题】:vb find nearest known colorvb 找到最近的已知颜色
【发布时间】:2013-11-28 18:51:29
【问题描述】:

我一直在尝试找到最接近的已知颜色,例如

dim nearestcolor as color= bitmap.getpixel(point.x,point.y)
if nearestcolor.toknowncolor = color.red then 

end if

我需要这样的东西,我需要看看 nearestcolor 是否看起来像红色

【问题讨论】:

标签: vba colors


【解决方案1】:

不确定这是否是您的答案,但您可以将颜色的 rgb 值视为 x、y、z 平面中的点,并使用几何计算已知颜色与像素颜色之间的距离。 http://freespace.virgin.net/hugo.elias/routines/r_dist.htm

【讨论】:

    【解决方案2】:
    Sub HoldCol()
        Dim colC, CC&
    ' all thanks to Mr Chip Pearson
        colC = Array("UNNAMED", _
                     "Black", "White", "Red", "Bright Green", "Blue", "Yellow", "Pink", "Turquoise", _
                     "Dark Red", "Green", "Dark Blue", "Dark Yellow", "Violet", "Teal", "Gray 25%", "Gray 50%", _
                     "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", _
                     "Dark Blue", "Pink", "Yellow", "Turquoise", "Violet", "Dark Red", "Teal", "Blue", _
                     "Sky Blue", "Light Turquoise", "Light Green", "Light Yellow", "Pale Blue", "Rose", "Lavender", "Tan", _
                     "Light Blue", "Aqua", "Lime", "Gold", "Light Orange", "Orange", "Blue Gray", "Gray 40%", _
                     "Dark Teal", "Sea Green", "Dark Green", "Olive Green", "Brown", "Plum", "Indigo", "Gray 80%")
        'cc  as collor to look at
        ' or use fill color to color cell
    
        CC = [m4].Interior.Color
    
        [m5].Interior.Color = CC    '[m4]  ' put color in cell   'out of need
        [m6] = [m5].Interior.ColorIndex    ' let vba find the nearest color index
        [n6] = CStr(colC([m6]))    ' get its name
        [m7].Interior.ColorIndex = [m6]
        ' may be offset 1 if you are using option base 1
        ' gets only close as you can see in cell "M7"
    'use variable names   in reality
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 2019-08-17
      • 2019-06-12
      • 2012-04-06
      • 2014-07-22
      • 1970-01-01
      • 2019-11-23
      相关资源
      最近更新 更多