Ein Histogramm gibt die Verteilung der Farbwerte wieder. Dieses Beispiel erstellt für jeden Farbkanal ein eigenes Histogramm. Dabei wird für jeden Farbton (0 .. 255) gezählt, wie oft er im Bild vorkommt. Es werden 3 Histogramme erstellt und graphisch als Balkendiagramm ausgegeben.
History
15.05.2003 Hinzugefügt
Autor: Dominik Auras <Dominik_auf_vbinside.de>
Code aus Form1.frm
Option ExplicitPrivate Sub Command1_Click()
Dim histogram_r(255) As Long, x As Long, y As Long, R As Long
Dim max As Long, factor As Double, curr As Long, G As Long, B As Long
Dim color As Long, histogram_g(255) As Long, histogram_b(255) As Long
For y = 0 To Picture1.ScaleHeight
For x = 0 To Picture1.ScaleWidth
color = Picture1.Point(x, y)
B = color And &HFF
G = (color \ 2 ^ 8) And &HFF
R = (color \ 2 ^ 16) And &HFF
histogram_r(R) = histogram_r(R) + 1
histogram_g(G) = histogram_g(G) + 1
histogram_b(B) = histogram_b(B) + 1
Next x
Next y
Debug.Print "Erstellt"
For x = 0 To 255
If histogram_r(x) > max Then
max = histogram_r(x)
End If
If histogram_g(x) > max Then
max = histogram_g(x)
End If
If histogram_b(x) > max Then
max = histogram_b(x)
End If
Next x
factor = 200 / max
x = 1
For y = 0 To 255
curr = histogram_r(y) * factor
Picture2.Line (x, Picture2.ScaleHeight - 1)-(x, _
Picture2.ScaleHeight - curr - 1), RGB(255, 0, 0), BF
curr = histogram_g(y) * factor
Picture2.Line (x + 1, Picture2.ScaleHeight - 1)-(x + 1, _
Picture2.ScaleHeight - curr - 1), RGB(0, 255, 0), BF
curr = histogram_b(y) * factor
Picture2.Line (x + 2, Picture2.ScaleHeight - 1)-(x + 2, _
Picture2.ScaleHeight - curr - 1), RGB(0, 0, 255), BF
x = x + 3
Next y
Debug.Print "Max:", max
Debug.Print "Factor:", factor
Debug.Print "Gezeichnet"
End Sub
Private Sub Form_Load()
Picture1.Picture = LoadPicture(App.Path & "\weights.bmp")
End Sub