Public Declare Function FloodFill Lib "gdi32" (ByVal HDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBits Lib "gdi32" (ByVal HDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Public Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
End Type
Private Const DIB_RGB_COLORS As Long = 0
Public Buf1() As RGBQUAD
Public Buf2() As RGBQUAD
'Convert Picture to Array
Public Sub Pic2Array(PicBox As PictureBox, ByRef PicArray() As RGBQUAD)
Dim Binfo As BITMAPINFO 'The GetDIBits API needs some Infos
ReDim PicArray(0 To PicBox.ScaleWidth - 1, 0 To PicBox.ScaleHeight - 1)
Dim RDelta As Double, GDelta As Double, BDelta As Double
Dim H As Single
Dim s As Single
Dim l As Single
Dim cMinus As Long, cPlus As Long
Dim notthere As Boolean
For X = 0 To UBound(PicAr, 1)
For Y = 0 To UBound(PicAr, 2)
R = PicAr(X, Y).rgbRed
G = PicAr(X, Y).rgbGreen
B = PicAr(X, Y).rgbBlue
'Calculate the hue
cMax = Maximum(R, G, B) 'iMax(iMax(R, G), B) 'Highest and lowest
cMin = Minimum(R, G, B) 'iMin(iMin(R, G), B) 'color values
cMinus = cMax - cMin 'Used to simplify the
cPlus = cMax + cMin 'calculations somewhat.
If cMax = cMin Then 'achromatic (r=g=b, greyscale)
H = 160
Else
RDelta = ((cMax - R) * 40 + 0.5) / cMinus
GDelta = ((cMax - G) * 40 + 0.5) / cMinus
BDelta = ((cMax - B) * 40 + 0.5) / cMinus
If cMax = CLng(R) Then
H = BDelta - GDelta
ElseIf cMax = CLng(G) Then
H = 80 + RDelta - BDelta
Else
H = 160 + GDelta - RDelta
End If
If H < 0 Then H = H + 240
End If
'For this we only need the red channel
PicAr(X, Y).rgbRed = H
'PicAr(x, y).rgbGreen = H
'PicAr(x, y).rgbBlue = H
Next Y
Next X
End Sub
Public Function Maximum(rR As Integer, rG As Integer, rB As Integer) As Integer
If (rR > rG) Then
If (rR > rB) Then Maximum = rR Else Maximum = rB
Else
If (rB > rG) Then Maximum = rB Else Maximum = rG
End If
End Function
Public Function Minimum(rR As Integer, rG As Integer, rB As Integer) As Integer
If (rR < rG) Then
If (rR < rB) Then Minimum = rR Else Minimum = rB
Else
If (rB < rG) Then Minimum = rB Else Minimum = rG
End If
End Function
'Check if a Color is ind a range X% from the actual point
Public Function SimilarColor(ByVal Red1 As Long, ByVal Green1 As Long, ByVal Blue1 As Long, ByVal Red2 As Long, ByVal Green2 As Long, ByVal Blue2 As Long, ByVal Percent As Long) As Boolean
'We have 255 Colors so wen need 100*2.55 to get all
Percent = Percent * 2.55
'Check if the color is in our range
If Abs(Red1 - Red2) <= Percent And Abs(Green1 - Green2) <= Percent And Abs(Blue1 - Blue2) <= Percent Then SimilarColor = True
End Function
Public Function SameColor(Red As Byte, Blue As Byte, Green As Byte) As Byte