guarda se ti piace
ti serve un form una pictrebox e una lista
codice:
Private Type Colore
Colore As Long
ricorrenze As Long
End Type
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Dim PicBits() As Byte, PicInfo As BITMAP
Dim Cnt As Long, BytesPerLine As Long
Private Sub Command1_Click()
Dim Colour() As Colore
Dim l As Long
Dim bFind As Boolean
GetObject Picture1.Image, Len(PicInfo), PicInfo
BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
ReDim Colour(0 To 0)
For Cnt = 1 To UBound(PicBits)
bFind = False
For l = LBound(Colour) + 1 To UBound(Colour)
If PicBits(Cnt) = Colour(l).Colore Then
bFind = True
Colour(l).ricorrenze = Colour(l).ricorrenze + 1
Exit For
End If
Next l
If bFind = False Then
ReDim Preserve Colour(0 To UBound(Colour) + 1)
Colour(UBound(Colour)).Colore = PicBits(Cnt)
End If
Next Cnt
For l = LBound(Colour) + 1 To UBound(Colour)
List1.AddItem "H&" & Hex(Colour(l).Colore) & " - " & Colour(l).ricorrenze
DoEvents
Next l
Picture1.Refresh
End Sub
Private Sub Form_Load()
Set Picture1.Picture = LoadPicture("f:\sergio.jpg")
End Sub