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,955 questions

51,897 answers

573 users

How to find the average between RGB colors c1 and c2 in VB.NET

3 Answers

0 votes
Imports System
Imports System.Drawing

Class Program
	Private Shared Function AverageColor(ByVal c1 As Color, ByVal c2 As Color) As Color
		Dim avgR As Integer = (CInt(c1.R) + CInt(c2.R)) \ 2
		Dim avgG As Integer = (CInt(c1.G) + CInt(c2.G)) \ 2
		Dim avgB As Integer = (CInt(c1.B) + CInt(c2.B)) \ 2

		Return Color.FromArgb(avgR, avgG, avgB)
	End Function

    Public Shared Sub Main()
        Dim c1 As Color = Color.FromArgb(255, 100, 50)
        Dim c2 As Color = Color.FromArgb(50, 170, 200)
		
        Dim average As Color = AverageColor(c1, c2)
		
        Console.WriteLine($"Average Color: {average}")
    End Sub
End Class



' run:
'
' Average Color: Color [A=255, R=152, G=135, B=125]
'

 



answered Jun 18, 2025 by avibootz
0 votes
Imports System
Imports System.Drawing

Class Program
    Public Shared Sub Main()
        Dim c1 As Color = Color.FromArgb(255, 100, 50)
        Dim c2 As Color = Color.FromArgb(50, 170, 200)

        ' Calculate average RGB values
        Dim avgR As Integer = (CInt(c1.R) + CInt(c2.R)) \ 2
        Dim avgG As Integer = (CInt(c1.G) + CInt(c2.G)) \ 2
        Dim avgB As Integer = (CInt(c1.B) + CInt(c2.B)) \ 2

        ' Format as hex string
        Dim average As String = $"#{avgR:X2}{avgG:X2}{avgB:X2}"

        Console.WriteLine($"Average Color (hex): {average}")
    End Sub
End Class


' run:
'
' Average Color (hex): #98877D
'

 



answered Jun 18, 2025 by avibootz
0 votes
Imports System
Imports System.Drawing

Class Program
    Public Shared Sub Main()
        Dim c1 As Color = Color.FromArgb(255, 100, 50)
        Dim c2 As Color = Color.FromArgb(50, 170, 200)
		
        Dim average As String = String.Format($"#{((CInt(c1.R) + CInt(c2.R)) \ 2):X2}{((CInt(c1.G) + CInt(c2.G)) \ 2):X2}{((CInt(c1.B) + CInt(c2.B)) \ 2):X2}")

        Console.WriteLine($"Average Color (hex): {average}")
    End Sub
End Class



' run:
'
' Average Color (hex): #98877D
'

 



answered Jun 18, 2025 by avibootz
...