1 |
#Region "Microsoft.VisualBasic::deb20948057d077ab9605a5ca6c33ec4, Microsoft.VisualBasic.Core\Extensions\Image\Colors\HexColor.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
#End Region
|
42 |
|
43 |
Imports System.Drawing
|
44 |
Imports System.Globalization
|
45 |
|
46 |
Namespace Imaging
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
Public Module HexColor
|
53 |
|
54 |
Public Function ConvertToRbg(HexColor As String) As Color
|
55 |
Dim Red As String
|
56 |
Dim Green As String
|
57 |
Dim Blue As String
|
58 |
HexColor = HexColor.Trim("#"c)
|
59 |
'"&H" &
|
60 |
Red = GetHexInteger(Mid(HexColor, 1, 2))
|
61 |
Green = GetHexInteger(Mid(HexColor, 3, 2))
|
62 |
Blue = GetHexInteger(Mid(HexColor, 5, 2))
|
63 |
Return Color.FromArgb(Integer.Parse(Red), Integer.Parse(Green), Integer.Parse(Blue))
|
64 |
End Function
|
65 |
|
66 |
Public Function HexToColor(hexColor As String) As Color
|
67 |
If hexColor.IndexOf("#"c) <> -1 Then
|
68 |
hexColor = hexColor.Replace("#", "")
|
69 |
End If
|
70 |
Dim red As Integer = 0
|
71 |
Dim green As Integer = 0
|
72 |
Dim blue As Integer = 0
|
73 |
If hexColor.Length = 6 Then
|
74 |
red = Integer.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier)
|
75 |
green = Integer.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier)
|
76 |
blue = Integer.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier)
|
77 |
ElseIf hexColor.Length = 3 Then
|
78 |
red = Integer.Parse(hexColor(0).ToString() + hexColor(0).ToString(), NumberStyles.AllowHexSpecifier)
|
79 |
green = Integer.Parse(hexColor(1).ToString() + hexColor(1).ToString(), NumberStyles.AllowHexSpecifier)
|
80 |
blue = Integer.Parse(hexColor(2).ToString() + hexColor(2).ToString(), NumberStyles.AllowHexSpecifier)
|
81 |
End If
|
82 |
Return Color.FromArgb(red, green, blue)
|
83 |
End Function
|
84 |
|
85 |
Public Function hexToRbgNew(Hex As String) As Color
|
86 |
Hex = Strings.Replace(Hex, "#", "")
|
87 |
Dim red As String = "&H" & Hex.Substring(0, 2)
|
88 |
Hex = Strings.Replace(Hex, red, "", , 1)
|
89 |
Dim green As String = "&H" & Hex.Substring(0, 2)
|
90 |
Hex = Strings.Replace(Hex, green, "", , 1)
|
91 |
Dim blue As String = "&H" & Hex.Substring(0, 2)
|
92 |
Hex = Strings.Replace(Hex, blue, "", , 1)
|
93 |
Return Color.FromArgb(red, green, blue)
|
94 |
End Function
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
<param name="c">Example: ``#ffffff``</param>
|
100 |
<returns></returns>
|
101 |
Public Function OLE(c As String) As Color
|
102 |
c = Strings.Replace(c, "#", "")
|
103 |
c = "&H" & c
|
104 |
ColorTranslator.FromOle(c)
|
105 |
End Function
|
106 |
End Module
|
107 |
End Namespace
|