VB取各颜色分量,将RGB转为HTML颜色.

本文提供了将RGB颜色值转换为HTML格式颜色代码的VBScript函数实现。包括获取红、绿、蓝三个颜色分量的函数及将这些分量组合成HTML颜色字符串的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
  1. '//取各颜色分量
  2. Public Function GetRedValue(COLOR As LongAs Integer '取得红色值
  3.        GetRedValue = COLOR And 
  4. End Function
  5. Public Function GetGreenValue(COLOR As LongAs Integer '取得绿色值
  6.        GetGreenValue = (COLOR And 65280) / 256
  7. End Function
  8. Public Function GetBlueValue(COLOR As LongAs Integer '取得蓝色值
  9.         GetBlueValue = (COLOR And &HFF0000) / 65536
  10. End Function
  11. '//将RGB转化为HTML颜色.
  12. Public Function GetHexColor(Red As Integer, Green As Integer, Blue As IntegerAs String 
  13. '将RGB颜色转换为HTML颜色
  14.   Dim StrRed As String, StrGreen As String, StrBlue As String
  15.   StrRed = Hex(Red)
  16.   StrGreen = Hex(Green)
  17.   StrBlue = Hex(Blue)
  18.   If Red <= 16 Then StrRed = "0" & StrRed
  19.   If Green <= 16 Then StrGreen = "0" & StrGreen
  20.   If Blue <= 16 Then StrBlue = "0" & StrBlue
  21.   GetHexColor = StrRed & StrGreen & StrBlue
  22. End Function
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值