VB中自定义一个调色板
来源:互联网 发布:安卓看片软件哪个好 编辑:程序博客网 时间:2024/06/10 07:21
- Option Explicit
- Dim Colors() As Variant
- Dim ColorToUse As Long
- Public Sub CreateColorPal(ColorPic As Object)
- Dim I As Long
- ColorPic.AutoRedraw = True
- ColorPic.Scale (0, 0)-(16, 3)
- Colors = Array(16777215, 14737632, 12632319, 12640511, _
- 14745599, 12648384, 16777152, 16761024, _
- 16761087, 192, 16576, 49344, _
- 49152, 12632064, 12582912, 12583104, _
- 12632256, 4210752, 8421631, 8438015, _
- 8454143, 8454016, 16777088, 16744576, _
- 16744703, 128, 16512, 32896, _
- 32768, 8421376, 8388608, 8388736, _
- 8421504, 0, 255, 33023, _
- 65535, 65280, 16776960, 16711680, _
- 16711935, 64, 4210816, 16448, _
- 16384, 4210688, 4194304, 4194368)
-
- For I = 0 To 15
- ColorPic.Line (I, 0)-(I + 1, 1), Colors(I), BF
- ColorPic.Line (I, 1)-(I + 1, 2), Colors(I + 16), BF
- ColorPic.Line (I, 2)-(I + 1, 3), Colors(I + 32), BF
- If I > 0 Then
- ColorPic.Line (I, 0)-(I, 3)
- End If
- Next I
- ColorPic.Line (0, 1)-(16, 1)
- ColorPic.Line (0, 2)-(16, 2)
- End Sub
- Public Function GetPicColor(ColorPic As Object, X As Single, Y As Single) As Long
- On Error Resume Next
- Dim W As Long, h As Long, c As Long
-
- W = ColorPic.ScaleWidth
- h = ColorPic.ScaleHeight
- If (X <= 0) Or (X >= W) Or (Y <= 0) Or (Y > h) Then
- Exit Function
- End If
- c = Fix(X) + Fix(Y) * 16
- ColorToUse = Colors(c)
- GetPicColor = ColorToUse
- End Function
- Private Sub Class_Initialize()
- Dim T As New ClsRev
- Call T.GetIniVal
- Set T = Nothing
- End Sub
- Public Function SetComFore(ObjWin As Object, Optional FontColor As Long = 0, Optional PTwidth As Long = 0)
- Dim Frm As Form
- Set Frm = ObjWin
-
- With SetFrmCom
- Call .ChComFcolor(Frm, .CjhPicToComm, .CjhFontSize, .CjhPicSize, FontColor, PTwidth)
- End With
- Unload SetFrmCom
- Set SetFrmCom = Nothing
- End Function
- Public Function PicToPic(BigWidth As Long, BigHeight As Long, ByRef SourPic As Object, ByRef ObjPic As Object)
- Dim RName As String
- Dim Pw As Long
- Dim Ph As Long
- Dim T1 As Double
- Dim T2 As Double
-
- Pw = SourPic.Width: Ph = SourPic.Height
-
- If SourPic.Picture <> 0 Then
- ObjPic.Visible = False
- T2 = Pw / Ph
- T1 = BigWidth / BigHeight
- If Pw > BigWidth Or Ph > BigHeight Then
- If T2 > T1 Then
- ObjPic.Width = BigWidth
- ObjPic.Height = BigWidth / T2
- Else
- ObjPic.Width = BigHeight * T2
- ObjPic.Height = BigHeight
- End If
- Else
- ObjPic.Width = Pw
- ObjPic.Height = Ph
- End If
- ObjPic.Picture = SourPic.Picture
- ObjPic.Move (BigWidth - ObjPic.Width) / 2, (BigHeight - ObjPic.Height) / 2
- ObjPic.Visible = True
- End If
- End Function