国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

用API函數取色后,如何將其分成RGB顏色?

2024-07-21 02:08:22
字體:
來源:轉載
供稿:網友



用api函數取色后,如何將其分成rgb顏色?


 

問題:

用api函數取色后,是一個10進制的數值,如何將其分成rgb顏色?
 



方法一:

用 hex 函數將數值轉換為 16 進制,然后,每兩個切分一下就可以得到 rgb 數值了
function c10torgb_1(lngcolor as long) as string
    dim strr as string
    dim strg as string
    dim strb as string
    strr = lngcolor mod 256
    strg = lngcolor / 256 mod 256
    strb = lngcolor / 256 / 256
    
    c10torgb_1 = strr & "_" & strg & "_" & strb
end function



sub test1()
    debug.print c10torgb_1(33023)
    debug.print rgb(255, 128, 0)
end sub



 



方法二:


【轉載】
如果要將vb的顏色轉換為colorref,需要使用oletranslatecolor函數。例子: 
    private declare function oletranslatecolor lib "olepro32.dll" _ 
     (byval ole_color as long, _ 
     byval hpalette as long, _ 
     pccolorref as long) as long 
     
    private sub getrbgfromolecolour(byval dwolecolour as long, r as long, g as long, b as long) 
     
     'pass a hex colour, return the rgb components 
     dim clrref as long 
     
     'translate ole color to valid color if passed 
     oletranslatecolor dwolecolour, 0, clrref 
     
     b = (clrref / 65536) and &hff 
     g = (clrref / 256) and &hff 
     r = clrref and &hff 
     
     text1(0).text = dwolecolour 
     text1(1).text = clrref 
     
    end sub 

    更完整的例子參考:http://www.mvps.org/vbnet/index.html?code/system/oletranslatecolor.htm

 







方法三:

用 hex 函數將數值轉換為 16 進制,然后,每兩個切分一下就可以得到 rgb 數值了


sub test1()
    debug.print c10torgb(33023)
    debug.print rgb(255, 128, 0)
end sub

function c10torgb(lnga as long) as string
    dim strr as string
    dim strg as string
    dim strb as string
    dim strhex as string
    
    strhex = right("00000" & hex(lnga), 6)
    
    'debug.print "b" & mid(strhex, 1, 2)
    'debug.print "g" & mid(strhex, 3, 2)
    'debug.print "r" & mid(strhex, 5, 2)
    
    strb = c16to10(mid(strhex, 1, 2))
    strg = c16to10(mid(strhex, 3, 2))
    strr = c16to10(mid(strhex, 5, 2))
    
    c10torgb = strr & "," & strg & "," & strb
    'debug.print c10torgb
end function


'以下函數將 16 進制數值轉換為 10 進制數值
private function c16to10(stra as string) as double
    dim a as double
    dim b as string
    dim c as double
    dim l as integer
    dim i as long
    l = len(stra)
    for i = 1 to l
        b = mid(stra, i, 1)
        select case b
            case "a"
                b = 10
            case "b"
                b = 11
            case "c"
                b = 12
            case "d"
                b = 13
            case "e"
                b = 14
            case "f"
                b = 15
        end select
        c = c + b * 16 ^ (l - 1)
        l = l - 1
    next
    c16to10 = c
    'debug.print c16to10
end function



如何取色你可以參考本站
http://access911.net/index.asp?board=4&recordid=71fab31e16dc



 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高台县| 梅河口市| 罗平县| 视频| 武川县| 鲁甸县| 沅江市| 封丘县| 镇远县| 深水埗区| 长丰县| 宁国市| 沁水县| 门头沟区| 藁城市| 广宁县| 铁岭县| 汾西县| 县级市| 巴彦淖尔市| 道孚县| 堆龙德庆县| 武功县| 琼结县| 五常市| 洪洞县| 军事| 钦州市| 宣恩县| 四会市| 如东县| 南靖县| 容城县| 栖霞市| 密云县| 漳浦县| 泗阳县| 繁昌县| 朔州市| 青神县| 沙洋县|