Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to convert from HEX color to RGB in VB.NET

1 Answer

0 votes
Imports System
Imports System.Globalization

Public Class HexToRgbConverter
    Public Shared Function HexToRgb(hex As String) As (Integer, Integer, Integer)
        ' Remove the '#' character if present
        hex = hex.TrimStart("#"c)

        ' Parse the hex string into an integer
        Dim hexValue As Integer = Integer.Parse(hex, NumberStyles.HexNumber)

        ' Extract the RGB components
        Dim r As Integer = (hexValue >> 16) And &HFF
        Dim g As Integer = (hexValue >> 8) And &HFF
        Dim b As Integer = hexValue And &HFF

        Return (r, g, b)
    End Function

    Public Shared Sub Main()
        Dim hexColor As String = "#FF5705"

        Dim rgb = HexToRgb(hexColor)

        Console.WriteLine($"RGB: ({rgb.Item1}, {rgb.Item2}, {rgb.Item3})")
    End Sub
End Class



' run:
'
' RGB: (255, 87, 5)
'  

 



answered Mar 6, 2025 by avibootz

Related questions

1 answer 166 views
166 views asked Dec 28, 2021 by avibootz
1 answer 44 views
1 answer 103 views
2 answers 99 views
2 answers 71 views
2 answers 78 views
...