微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

几个颜色转换函数源码

VB的几个颜色转换函数源码

'把ARGB转RGB。
Public Function ARGBToRGB(ByVal Color As Long) As Long
Dim R As Long,G As Long,B As Long
R = (Color And &HFF0000) \ &H10000
G = Color And &HFF00&
B = (Color And &HFF&) * &H10000
ARGBToRGB = R Or G Or B
End Function

'----------RGB转24位色--------------------
Private Function RGB(ByVal Red As Byte,ByVal Green As Byte,ByVal Blue As Byte) As Long
RGB = Red + Green * 256 + Blue * 65536
End Function

'将一种颜色分为三色
Public Function GetRGB(ByVal Color As Long,ByRef Red As Integer,ByRef Green As Integer,ByRef Blue As Integer) As Boolean
Red = Color And &HFF '拆分颜色
Green = (Color And 65280) \ 256
Blue = (Color And &HFF0000) \ 65536
End Function

'将RGB颜色转换成ARGB格式
Public Function RGBToARGB(ByVal Color As Long,Optional ByVal Alpha As Long = &HFF000000) As Long
'RGB 颜色 = B*256*256+G*256+R,=00BbGgRr
'Argb颜色 =A*256*256*256+R*256*256+G*256+B,=AaRrGgBb
RGBToARGB = Alpha Or ((Color And &HFF0000) \ &H10000) Or (Color And &HFF00&) Or ((Color And &HFF&) * &H10000)
End Function

'-----------ARGB转32位色。写法1--------------------
Private Function ARGB(ByVal Alpha As Byte,ByVal Red As Byte,ByVal Blue As Byte) As Long
Dim RGBColor As Long,NewAlpha As Long
RGBColor = Red + Green * 256 + Blue * 65536
NewAlpha = "&H" & Hex(Alpha) & "000000"
ARGB1 = NewAlpha Or ((RGBColor And &HFF0000) \ &H10000) Or (RGBColor And &HFF00&) Or ((RGBColor And &HFF&) * &H10000)
End Function
'-----------ARGB转32位色。写法2--------------------
Private Function ARGB(ByVal Alpha As Byte,NewAlpha As Long,i As Long,lMask As Long
RGBColor = Red + Green * 256 + Blue * 65536
NewAlpha = Alpha
'--------------------进行移位运算,左移24位----------------------
For i = 1 To 24
lMask = 0
If (NewAlpha And &H40000000) <> 0 Then lMask = &H80000000
NewAlpha = (NewAlpha And &H3FFFFFFF) * 2 Or lMask
Next
ARGB = NewAlpha Or ((RGBColor And &HFF0000) \ &H10000) Or (RGBColor And &HFF00&) Or ((RGBColor And &HFF&) * &H10000)
End Function

'-----------ARGB转32位色。写法3--------------------
Private Function ARGB(ByVal Alpha As Byte,ByVal Blue As Byte) As Long
Dim A As String,R As String,G As String,B As String
If Len(Hex(Alpha)) < 2 Then A = 0 & Hex(Alpha) Else A = Hex(Alpha)
If Len(Hex(Red)) < 2 Then R = 0 & Hex(Red) Else R = Hex(Red)
If Len(Hex(Green)) < 2 Then G = 0 & Hex(Green) Else G = Hex(Green)
If Len(Hex(Blue)) < 2 Then B = 0 & Hex(Blue) Else B = Hex(Blue)
ARGB = "&H" & A & R & G & B
End Function

'取得任意颜色的反色
Public Function OppColor(ByVal Color As Long) As Long

Dim Red As Integer,Green As Integer,Blue As Integer
Red = Color And &HFF '拆分颜色
Green = (Color And 65280) \ 256
Blue = (Color And &HFF0000) \ 65536

Red = 255 - Red
Green = 255 - Green
Blue = 255 - Blue

If Red < 0 Then Red = 0
If Red > 255 Then Red = 255

If Green < 0 Then Green = 0
If Green > 255 Then Green = 255

If Blue < 0 Then Blue = 0 If Blue > 255 Then Blue = 255 OppColor = RGB(Red,Green,Blue) '得到反色 End Function

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 -------------------------------- 数字类型的格式化 --------------------------------     固定格式参数:     General Number 普通数字,如可以用来去掉千位分隔号     format$("100,1
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和系统设置的区域语言的日期和时间格式相关。意思是尽管你用诸如 Format(Now, "MM/dd/yyyy"),如果系统的设置格式区域语言的日期和时间格式分隔符是"-",那他还会显示为 MM-dd-yyyy     只有拼凑: <%response.write
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 ‘添加后还需要一个From用来显示错误。如果到这步还不会则需要先打好基础啦 ‘======================================================== ‘以下事件
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.Net下的语言工具开发BOS插件是一件很愉快的事情,其中缘由不言而喻,而本文则是个人首创,实现在了用V
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integer, y As Integer, subStr As String If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) 2 Dim path As String, hash As String 3 For Each fil
  Imports MySql.Data.MySqlClient Public Class Form1 ‘ GLOBAL DECLARATIONS Dim conString As String = "Server=localhost;Database=net2;Uid=root;Pwd=123456;" Dim con As New MySqlConnection
‘導入命名空間 Imports ADODB Imports Microsoft.Office.Interop   Private Sub A1() Dim Sql As String Dim Cnn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim S As String   S = "Provider=OraOLEDB.Oracl
Imports System.IO Imports System.Threading Imports System.Diagnostics Public Class Form1 Dim A(254) As String    Function ping(ByVal IP As Integer) As String Dim IPAddress As String IPAddress = "10.0.
VB运行EXE程序,并等待其运行结束 参考:https://blog.csdn.net/useway/article/details/5494084 Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Pr