1
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
|
Private Function GetAverageColor(ByVal img As Bitmap, _
Optional ByVal Quality As Integer = 10) As Color
Dim cDots As New ArrayList
Dim Red, Blue, Green As Integer
Dim HoriPoints As Integer = Math.Floor(img.Width / Quality)
Dim VertiPoints As Integer = Math.Floor(img.Height / Quality)
Dim result As Color = Color.White
Try
For i = 1 To Quality
Dim x = HoriPoints * i - 1
For ypos = 1 To Quality
Dim y = VertiPoints * ypos - 1
cDots.Add(img.GetPixel(x, y))
Next
Next
For Each c As Color In cDots
Red += c.R
Blue += c.B
Green += c.G
Next
Dim aColor As Color = Color.FromArgb(Red / cDots.Count, _
Green / cDots.Count, _
Blue / cDots.Count)
result = aColor
Catch ex As Exception
Return result
End Try
Return result
End Function
|